is string and String same?
Possible Duplicate:
What's the difference between String and string?
When does it matter whether you use int versus Int32, or string versus String?
in visual studio when i am typing string,it shows two suggestions as
is both 'string' and 'String' same? Visual studio shows the same description for both.
so if they are same what is the need for keeping two different things which perform the same function?
Yeah there is technically no difference at all with your use of it, as this article confirms. As said in the answer, it is considered best practice if you use string
.
Hope this clears it up for you!
string
is nothing more than an alias for System.String
.
The same holds for int
being an alias for System.Int32
(see this answer).
I also agree with the general guideline of using String
for static function calls such as String.Format
rather than string.Format
(although I prefer string.Empty
), and using string
for objects ( string hello = "world";
).
But, at this point, it's all a matter of preferences and conventions.
Also MSDN says the same, string
is just an alias for System.String
. If you want to see a full map of types that are aliased in C#, you can refer here: Data Types (C# vs. Java).
下一篇: 是字符串和字符串相同吗?