What is the difference between these two declarations?
string str;
String str;
What is the difference between these two declarations?
string str;
String str;
In normal usage, string
and String
are identical; string
is simply an alias for global::System.String
. There are some edge-cases, though:
using System;
to use String
- you don't for string
class String {}
, then String
refers to that (this would be a silly thing to do, of course). You can't define a class called string
(although @string
is fine)There is no difference. string (lower case) is just an alias for System.String.
string is a c# keyword. String is the System.String .NET type.
The C# compiler provided by MS maps the string keyword to the System.String .NET type, so they are equivalent.
Nothing really, in C# the type keywords actually are synonyms for the types. So int = System.Int32 short = System.Int16 and string = System.String.
String is an alias for System.String object, so none.
System.String is a Common Type System type necessary for interaction with other .NET languages. "string" is just C# shortcut to this name (in the same way int is shortcut to System.Int32)
They are the same, no difference, string is simply an alias for the System.String type, there are other similar cases in C#, like int and System.Int32, long and System.Int64 (see another related question)
Curiously though, whilst you can use alias in your code in place of the fully qualified types, you still need to know the underlying type when you use the Convert class because there's no ToInt or ToLong methods but only ToInt32 and ToInt64..