Wednesday, March 28, 2012

String.Empty or string.Empty

Howdie y'all,

Can somebody just tell me what's the difference between String.Empty and string.Empty

I use C# in VWD and the 'String' shows up green and the 'string' shows up blue.

Thanks,

Wes

String (with a big S) is actually the System.String class from the Framework Class Library. string (with a small s) is the C# keyword alias for the System.String class, which is why it is blue. There is no difference in their use, other than the case of the S, and the compiler generates identical code in both cases. This is one of the very few cases in C# where case doesn't matter.

I've seen coding standards that mandate the use of the Framework type names (e.g. Int32 rather than C#'s int). In some cases this is because there are methods on types, such as ToInt32(), but I'm ambivalent to this as an argument.


Short and clear!!!

Thanks a lot(I don't have to redo my code now)...

Wes

P.S. what do you use as Standard?


I tend to favour the coding standard as offered by Juval Lowy, as found athttp://www.idesign.net


Lance Hunt's coding standards also recommends using the language alias versus the .NET type, i.e., string vs. String

http://weblogs.asp.net/lhunt/archive/2004/08/17/CSharpCodingStandardsv113.aspx

but still the question remains... why?

0 comments:

Post a Comment