Difference b/w String and string [duplicate]
Possible Duplicates:
In C# what is the difference between String and string String vs string in C#
Hi,
Can anyone tell me the difference between the two lines of code below:
public const String sample = "Sample";
public const string sample2 = "Sample2";
Both "String" and "string" are of System.String.
Thanks in advance.
These data types are exactly the same, as string is just an alias for the class String. If you have a look, there are similar capitalized and non capitalized versions of int, float and similar classes.
Have a look here for a more detailed answer.
There are the same
string is an alias in the C# for .Net System.String, like int is for Int32, long is for int64 and etc. C# string replaced by System.String during compilation
No difference what so ever - in fact you can write the following code:
String sample = "Sample";
string sample2 = sample;
Both maps to the same IL string type
String vs string in C#
String stands for System.String and it is a .NET Framework type. string is an alias in the C# language for System.String. Both of them are compiled to System.String in IL (Intermediate Language), so there is no difference. Choose what you like and use that. If you code in C#, I'd prefer string as it's a C# type alias and well-know by C# programmers.
String is CTS type but string is c# string object.
You can use String to any of dot net language.
both are the same string -> c# type which gets converted to String -> .net type
String is the .NET class for the CLR built-in string type. string is the C# language identifier that maps to the CLR String type. They are the same thing.
"string" is actually an alias for System.String. They're the same.
Try:
typeof(string) == typeof(String) == typeof(System.String)
Nothing really, in C# the type keywords actually are synonyms for the types. So int = System.Int32 short = System.Int16 and string = System.String.
They have the keywords because they are easier to remember and programmers coming from other languages like c/c++ would also be familiar with these types.
Anyway, look at the C# keyword reference and you can find these things out. This was taken from the string keyword reference.
The string type represents a string of Unicode characters. string is an alias for String in the .NET Framework. Strings are immutable--the contents of a string object cannot be changed after the object is created.
精彩评论