Quantcast
Channel: What is the difference between String and string in C#? - Stack Overflow
Viewing all articles
Browse latest Browse all 69

Answer by Ted Mucuzany for What is the difference between String and string in C#?

$
0
0

All the above is basically correct. One can check it. Just write a short method

public static void Main(){    var s = "a string";}

compile it and open .exe with ildasm to see

.method private hidebysig static void  Main(string[] args) cil managed{  .entrypoint  // Code size       8 (0x8)  .maxstack  1  .locals init ([0] string s)  IL_0000:  nop  IL_0001:  ldstr      "a string"  IL_0006:  stloc.0  IL_0007:  ret} // end of method Program::Main

then change var to string and String, compile, open with ildasm and see IL does not change. It also shows the creators of the language prefer just string when difining variables (spoiler: when calling members they prefer String).


Viewing all articles
Browse latest Browse all 69

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>