string vs String functions
-
I have been developing for a while now, mostly in VB. But now I have seen the light and joined the C# parade. Anywho, is there a difference between the functions and use of
string.
functions andString.
functions? I use.Empty
,.IsNullOrEmpty
, and.Format
all the time. Does it really matter if I usestring.
orString.
? I know that one is a type, but besides the color in VS, what is the difference, and should I use one or the other?Success is the happy feeling you get between the time you do something and the time you tell a woman what you did. --Dibert
-
I have been developing for a while now, mostly in VB. But now I have seen the light and joined the C# parade. Anywho, is there a difference between the functions and use of
string.
functions andString.
functions? I use.Empty
,.IsNullOrEmpty
, and.Format
all the time. Does it really matter if I usestring.
orString.
? I know that one is a type, but besides the color in VS, what is the difference, and should I use one or the other?Success is the happy feeling you get between the time you do something and the time you tell a woman what you did. --Dibert
string
is a C# keyword that is an alias to System.String. If you have "using System;" in your file and you don't have any other class named String, then String (the class) and string (the C# keyword) are equivalent. OtherwiseString
may refer to your own String class, whilestring
always refers to the built-in string class. Another difference: you may useString
as a name for local variables (if you like to confuse people reading your code), butstring
is reserved. But normally using string or String makes no difference, both compile to the same IL. -
string
is a C# keyword that is an alias to System.String. If you have "using System;" in your file and you don't have any other class named String, then String (the class) and string (the C# keyword) are equivalent. OtherwiseString
may refer to your own String class, whilestring
always refers to the built-in string class. Another difference: you may useString
as a name for local variables (if you like to confuse people reading your code), butstring
is reserved. But normally using string or String makes no difference, both compile to the same IL.I've always been told to always use the lower case as it makes it easier to read on others who are viewing your code (unless they come from jave)! Also, you should learn all about string builders. They are the best item for creating multi component strings and they only are created once, not every time you add another string element. Sorry for the diatribe.
_____________________________________________________________________ Our developers never release code. Rather, it tends to escape, pillaging the countryside all around. The Enlightenment Project (paraphrased comment) Visit Me at GISDevCafe
-
string
is a C# keyword that is an alias to System.String. If you have "using System;" in your file and you don't have any other class named String, then String (the class) and string (the C# keyword) are equivalent. OtherwiseString
may refer to your own String class, whilestring
always refers to the built-in string class. Another difference: you may useString
as a name for local variables (if you like to confuse people reading your code), butstring
is reserved. But normally using string or String makes no difference, both compile to the same IL.I would not recommend writing your own String class; too confusing ! :)
Luc Pattyn [My Articles]
-
I have been developing for a while now, mostly in VB. But now I have seen the light and joined the C# parade. Anywho, is there a difference between the functions and use of
string.
functions andString.
functions? I use.Empty
,.IsNullOrEmpty
, and.Format
all the time. Does it really matter if I usestring.
orString.
? I know that one is a type, but besides the color in VS, what is the difference, and should I use one or the other?Success is the happy feeling you get between the time you do something and the time you tell a woman what you did. --Dibert
There really isn't any difference.
string
is the C# alias forSystem.String
, which is the actual CLR data type. I personally usestring
when declaring variables andString
when calling functions (like.Empty
,.IsNullOrEmpty
, and.Format
) as I think it makes it a little clearer; but that is simply personal preference andstring.Format
is exactly the same asString.Format
.----------------------------- In just two days, tomorrow will be yesterday.
-
I have been developing for a while now, mostly in VB. But now I have seen the light and joined the C# parade. Anywho, is there a difference between the functions and use of
string.
functions andString.
functions? I use.Empty
,.IsNullOrEmpty
, and.Format
all the time. Does it really matter if I usestring.
orString.
? I know that one is a type, but besides the color in VS, what is the difference, and should I use one or the other?Success is the happy feeling you get between the time you do something and the time you tell a woman what you did. --Dibert
String may refer to your own class, string refers to the inbuilt string class
Keshav Kamat :) India