为什么DOTNET的char.IsLower()的静态方法? [英] Why is dotnet's char.IsLower() a static method?

查看:179
本文介绍了为什么DOTNET的char.IsLower()的静态方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎违背了每一个设计方针。 接受单个T类型的参数静态方法通常应该只是一个成员方法。

This seems to go against every design guideline. A static method that accepts a single argument of type T should usually just be a member method.

它是如此的bizzare其实我不得不发布<一个href="http://stackoverflow.com/questions/389100/is-there-a-built-in-islowercase-in-net">StackOverflow问题了解IsUpper存在(因为它没有自动完成显示)

It's so bizzare I actually had to post a StackOverflow question to understand IsUpper exists (as it didn't show up in auto-completion)

修改

我明白我刚才的发言需要一点解释。的一个良好的设计的一个例子是String.ToLower()。相反,它被作为原型静态无效TOLOWER(字符串FOO),它是一个成员方法。这是pretty的明显(至少对我来说),这同样应按住char.IsLower()。

I understand my earlier statement needs a little explaining. An example of a good design is String.ToLower(). Instead of it being prototyped as static void ToLower(String foo), it is a member method. It's pretty obvious (to me at least) that the same should hold for char.IsLower().

推荐答案

在结构实例方法的不是线程安全的。 在另一方面静态方法

Instance methods on structures are not thread safe. Static methods on the other hand are.

静态方法获得结构的副本,实例方法有管理的指针。通过指针访问数据不是胎面操作安全,很容易导致竞争条件。

Static methods receive a copy of the structure, instance methods a managed pointer. Accessing data through a pointer is not a tread safe operation and can easily lead to race conditions.

这就是为什么在结构/图元大部分方法是静态的,而不是实例。

That's why most methods on structures/primitives are static and not instance.

硒这里类似的问题。

<一个href="http://stackoverflow.com/questions/370859/why-isnan-is-a-static-method-on-the-double-class-instead-of-an-instance-property#370996">Why IsNan是Double类的静态方法,而不是一个实例属性?

这篇关于为什么DOTNET的char.IsLower()的静态方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆