C#.Net case
Why does C#.Net allow the declaration of the string object to be case-insensitive?
String sHello = "Hello";
string sHello = "Hello";
Both the lower-case and upper-case S of the word String are acceptable and this seems to be the only object that allows this.
Can anyone explain why?
string
is a language keyword while System.String
is the type it aliases.
Both compile to exactly the same thing, similarly:
int
is System.Int32
long
is System.Int64
float
is System.Single
double
is System.Double
char
is System.Char
byte
is System.Byte
short
is System.Int16
ushort
is System.UInt16
uint
is System.UInt32
ulong
is System.UInt64
I think in most cases this is about code legibility - all the basic system value types have aliases, I think the lower case string
might just be for consistency.
Further to the other answers, it's good practice to use keywords if they exist.
Eg you should use string rather than System.String .
"String" is the name of the class. "string" is keyword that maps this class.
it's the same like
... and so on...
链接地址: http://www.djcxy.com/p/3564.html下一篇: C#.Net案例