28

Newbie here, in C# what is the difference between the upper and lower case String/string?

1

8 Answers 8

35

String uses a few more pixels than string. So, in a dark room, it will cast a bit more light, if your code is going to be read with light-on-dark fonts. Deciding on which to use can be tricky - it depends on the price of lighting pixels, and whether your readership wants to cast more light or less. But c# gives you the choice, which is why it is all-around the best language.

Sign up to request clarification or add additional context in comments.

5 Comments

I lol'ed and had to explain why to a coworker...
I am a better programmer for knowing the "Correct" answer now. Thank you! :)
In the good old times, most stuff was even completely case-insensitive. WRITING ALL IN UPPERCASE GAVE A LOT OF GREEN LIGHT ON A BLACK CRT-TUBE. But in these dark days, we write black on white and the situation has per(re)versed. LOL-good answer.
saves toner when printing too
or wastes it if you prefer String. your choice...
16

Nothing - both refer to System.String.

Comments

7

"String" is the underlying CLR data type (class) while "string" is the C# alias (keyword) for String. They are synonomous. Some people prefer using String when calling static methods like String.Format() rather than string.Format() but they are the same.

Comments

1

String is short version of System.String, the common type system (CTS) Type used by all .Net languages. string is the C# abbreviation for the same thing...

like

  • System.Int32 and int
  • System.Int16 and short,

etc.

Comments

1

An object of type "String" in C# is an object of type "System.String", and it's bound that way by the compiler if you use a "using System" directive, like so: using System; ... String s = "Hi"; Console.WriteLine(s); If you were to remove the "using System" statement, I'd have to write the code more explicitly, like so: System.String s = "Hi"; System.Console.WriteLine(s); On the other hand, if you use the "string" type in C#, you could skip the "using System" directive and the namespace prefix: string s = "Hi"; System.Console.WriteLine(s); The reason that this works and the reason that "object", "int", etc in C# all work is because they're language-specific aliases to underlying .NET Framework types. Most languages have their own aliases that serve as a short-cut and a bridge to the .NET types that existing programmers in those languages understand.

Comments

0

no difference. string is just synonym of String.

Comments

0

string is an alias for String in the .NET Framework.

Comments

0

String is type coming from .NET core (CLR).

string is C# type, that is translated to String in compiled IL.

Language types are translated to CLR types.

Comments