1) Is there a difference between String and string (or between Object and object)?
2) Why can't you just create an empty string? there is no zero parameter constructor for string...
1) Is there a difference between String and string (or between Object and object)?
2) Why can't you just create an empty string? there is no zero parameter constructor for string...
"string" is just an alias for "System.String", just like "int" is an alias for "System.Int32" and "object" for "System.Object". Whichever you use is up to you.
How about:
Code:string EmptyString1 = ""; string EmptyString2 = System.String.Empty;
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Ah, ok.
II want the new keyword so I can instantiate a new string so I can use it outside a function. Like:but that is not right, because string doesn't have such a constructor. I could do new string(new char[0]) or something like that, but again... why not have a standard constructor for a null string.Code:void myMyAriAri(object o) { ((myClass)o).str = new string(String.Empty); }
Of course, I could just use String.Copy() at one point and not use the new keyword. But, why not have the option?
C# is managed and System.String is immutable. Just do "((myClass)o).str = System.String.Empty;".
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
immutable... I wasn't aware of that. So it makes sense now.