When does it matter whether you use int versus Int32, or string versus String?

前端 未结 8 653
慢半拍i
慢半拍i 2021-01-19 14:02

In C#, the keywords for built-in types are simply aliases for corresponding types in the System namespace.

Generally, it makes no difference whether yo

8条回答
  •  太阳男子
    2021-01-19 14:36

    The only situation I can think of in which you are required to use the aliases in a form where you might otherwise be able to use a class name is in the definition of enum types:

    public enum MyEnum:Byte //will not compile
    
    public enum MyEnum:byte //correct
    

    Notice also that the definition of an enum requires use of the alias keyword, while when defining code members that can accept any enumerated type, you use the class name Enum.

    Lastly, you can never specify System.ValueType as a base class or generic type parameter; you instead use the struct keyword, which is essentially an alias for an object deriving from ValueType.

提交回复
热议问题