Base types or Complex types?
Possible Duplicate:
What is the difference between Bool and Boolean types in C#
最近我为一个Web应用程序做了很多C编程。我的团队还没有决定我们应该使用基类型还是复杂类型。
不同类型的优点是什么?
Feks:
1 2 | Object vs object Boolean vs bool |
等等…
谢谢!
没有区别——
请注意,默认情况下,StyleCop将强制执行此实践。相关规则为SA1121。
当然,对于这个规则是否有效,人们有不同的看法。我建议阅读这个问题:c-stylecop-sa1121:usebuiltintypealias-readability规则。
C:"System.Object"和"Object"之间的区别
乔恩·斯基特:
string is an alias for global::System.String. It's simply syntactic
sugar. The two are exactly interchangable, and there'll be no
difference in the compiled code.Personally I use the aliases for variable names etc, but I use the CLR
type names for names in APIs, for example:
1
2
3 public int ReadInt32() // Good, language-neutral
public int ReadInt() // Bad, assumes C# meaning of"int"(Note that the return type isn't really a name - it's encoded as a
type in the metadata, so there's no confusion there.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | object === System.Object string === System.String bool === System.Boolean byte === System.Byte sbyte === System.SByte short === System.Int16 ushort === System.UInt16 int === System.Int32 uint === System.UInt32 long === System.Int64 ulong === System.UInt64 float === System.Single double === System.Double decimal === System.Decimal char === System.Char |