Saturday 29 December 2007 @ 11:12 am
So, technically, String and string mean exactly the same thing in C#. string, is an alias for String (aka a shorthand) for System.String. So, when should use which? It seems that the convention is to use string when you are referring to an object and String when you are referring specifically to the string class.
This is basically what is said at this URL: http://en.csharp-online.net/CSharp_String_Theory%E2%80%94string_versus_String
Juval Lowy has some coding standards at http://www.idesign.net that says basically the same thing. From the document on IDesign’s web site the following examples show what is best practices (which I completely agree with).
That’s it for now.











December 31st, 2007 at 7:36 am
In VB.NET, it will always capitalize the S for you, therefore you don’t even have to think about it. Case-sensitive languages should be deprecated, IMO.
December 31st, 2007 at 8:22 am
I’m more thinking that things like S or s doesn’t make a difference should be deprecated (like what’s in this post). I’ve grown up using case sensative languages so I just always expect case will make a difference. VB just confuses me.
January 1st, 2008 at 11:26 pm
one doubt.
which is better to use?
String.Empty or string.Empty? and why?
Or are they both same since string is an alias of String?
January 5th, 2008 at 9:39 pm
String.Empty or string.Empty? and why?
Use string.empty when you have a space after the = and String.Empty when you are starting on a new line.
Why? Because people just need rules, apparently.
August 28th, 2008 at 11:35 am
haha, nice answer, Rusty
March 11th, 2009 at 7:27 am
No that doesn’t make sense Rusty.
Use like so:
String nameOfSomething = String.Empty;
i mean String is a class and who starts a class name in lowercase? Right knowone