What is the difference between String and string in C#?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What is the difference between String and string in C#?
What can u do with string that you cant do with String, vice versa?
 
Bruce said:
What is the difference between String and string in C#?

"string" is a keyword; you can't use "string" as an identifier.
"String" is not a keyword, and you can use it as an identifier:

string String = "Isn't this confusing?";

That's the only difference. The keyword "string" is an alias for
"System.String"; aside from the keyword issue, the two are exactly
equivalent. typeof(string) == typeof(String) == typeof(System.String).
 
Bruce One said:
What is the difference between String and string in C#?
What can u do with string that you cant do with String, vice versa?

string is just a shorthand for String. There is no difference
whatsoever in capabilities.

(There's a very slight difference in terms of hoops you need to go
through if you want to name a variable "string", but I suggest you
don't create variables called either String or string.)
 
Why should not create using system? If it has the same result as
System.String and its pretty quicker, why not?
 
Why should not create using string (lowercase) ? If it has the same result
as System.String and its pretty quicker, why not?
 
Bruce One said:
Why should not create using string (lowercase) ? If it has the same result
as System.String and its pretty quicker, why not?

I'm not sure what you mean by "create using string"?

I certainly tend to use the C# shorthands rather than the full type
names (eg float instead of Single) but it sounds like you're proposing
something slightly different...
 
Back
Top