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

Answer by Ran Turner for What is the difference between String and string in C#?

$
0
0

Essentially, there is no difference betweenstring and String in C#.

String is a class in the .NET framework in the System namespace under System.String, Whereas, lower case string is an alias of System.String.

Logging the full name of both types can prove this

string s1= "hello there 1";String s2 = "hello there 2";Console.WriteLine(s1.GetType().FullName); // System.StringConsole.WriteLine(s2.GetType().FullName); // System.String

It is recommended to use string over String but it's really a matter of choice. Most developers use string to declare variables in C# and use System.String class to use any built-in string methods like for an example , the String.IsNullOrEmpty() method.


Viewing all articles
Browse latest Browse all 69

Trending Articles



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