What exactly is the difference between declaring a string variable with the lower case version of string as opposed to String with a cap S? Whats the upper case 'String' for?
I think the above have answered the question, but my personal preference is to use 'string' when dealing with the type, and 'String' when dealing with functions of the type. Eg:
Code:
string foo = "ABC"; // should really use var here and let the compiler determine the type, but for examples' sake...
string bar = "XZY";
var otherString = String.Format("Foo: {0}, Bar: {1}", foo, bar);
I think the above have answered the question, but my personal preference is to use 'string' when dealing with the type, and 'String' when dealing with functions of the type. Eg:
Code:
string foo = "ABC"; // should really use var here and let the compiler determine the type, but for examples' sake...
string bar = "XZY";
var otherString = String.Format("Foo: {0}, Bar: {1}", foo, bar);
I always use the aliases when I'm coding, though there are a few things that don't make too much sense for the aliases.
as an example Convert.ToInt64 returns something that I would define as a long, which doesn't feel quite right but I'll still stick to aliases.
I always use the aliases when I'm coding, though there are a few things that don't make too much sense for the aliases.
as an example Convert.ToInt64 returns something that I would define as a long, which doesn't feel quite right but I'll still stick to aliases.
It's not that it's confusing, but if the guidance is to use aliases in your code why is the method not called ToLong?
Especially when there are properties/methods called LongLength and LongCount() on the Array type and in LINQ respectively.
It is for me when going back and forth between c# and c++ seeing as c++ treats a long as a 32-bit integer
string all the way for me now, used to using String for method calling but stopped to just have uniformity I think? Was a while ago now and kinda stuck heh.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.