<p>What are the differences between these two and which one should I use?</p>
<pre><code>string s = &quot;Hello world!&quot;;
String s = &quot;Hello world!&quot;;
</code></pre>

[{'answer_id': 7077, 'author': 'Derek Park', 'author_id': 872, 'author_profile': 'https://Stackoverflow.com/users/872', 'pm_score': 14, 'selected': True, 'text': '<p><a href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/string" rel="noreferrer"><code>string</code></a> is an alias in C# for <a href="https://learn.microsoft.com/en-us/dotnet/api/system.string" rel="noreferrer"><code>System.String</code></a>.<br />\nSo technically, there is no difference.  It\'s like <a href="https://stackoverflow.com/questions/62503/c-int-or-int32-should-i-care"><code>int</code> <em>vs.</em> <code>System.Int32</code></a>.</p>\n<p>As far as guidelines, it\'s generally recommended to use <code>string</code> any time you\'re referring to an object.</p>\n<p>e.g.</p>\n<pre><code>string place = &quot;world&quot;;\n</code></pre>\n<p>Likewise, I think it\'s generally recommended to use <code>String</code> if you need to refer specifically to the class.</p>\n<p>e.g.</p>\n<pre><code>string greet = String.Format(&quot;Hello {0}!&quot;, place);\n</code></pre>\n<h3>This is the style that Microsoft tends to use in <a href="https://learn.microsoft.com/en-us/dotnet/api/system.string.format#examples" rel="noreferrer">their examples</a>.</h3>\n<p>It appears that the guidance in this area may have changed, as <a href="https://github.com/StyleCop" rel="noreferrer">StyleCop</a> now enforces the use of the C# specific aliases.</p>\n'}, {'answer_id': 7079, 'author': 'Ronnie', 'author_id': 193, 'author_profile': 'https://Stackoverflow.com/users/193', 'pm_score': 8, 'selected': False, 'text': "<p><code>System.String</code> is the .NET string class - in C# <code>string</code> is an alias for <code>System.String</code> - so in use they are the same.</p>\n\n<p>As for guidelines I wouldn't get too bogged down and just use whichever you feel like - there are more important things in life and the code is going to be the same anyway.</p>\n\n<p>If you find yourselves building systems where it is necessary to specify the size of the integers you are using and so tend to use <code>Int16</code>, <code>Int32</code>, <code>UInt16</code>, <code>UInt32</code> etc. then it might look more natural to use <code>String</code> - and when moving around between different .net languages it might make things more understandable - otherwise I would use string and int.</p>\n"}, {'answer_id': 7081, 'author': 'urini', 'author_id': 373, 'author_profile': 'https://Stackoverflow.com/users/373', 'pm_score': 8, 'selected': False, 'text': "<p>Lower case <code>string</code> is an alias for <code>System.String</code>.\nThey are the same in <code>C#</code>.</p>\n\n<p>There's a debate over whether you should use the System types (<code>System.Int32</code>, <code>System.String</code>, etc.) types or the <code>C# aliases</code> (<code>int</code>, <code>string</code>, etc). I personally believe you should use the <code>C# aliases</code>, but that's just my personal preference.</p>\n"}, {'answer_id': 12863, 'author': 'Luke Foust', 'author_id': 646, 'author_profile': 'https://Stackoverflow.com/users/646', 'pm_score': 9, 'selected': False, 'text': '<p>The best answer I have ever heard about using the provided type aliases in C# comes from Jeffrey Richter in his book <a href="https://rads.stackoverflow.com/amzn/click/com/0735621632" rel="noreferrer" rel="nofollow noreferrer">CLR Via C#</a>. Here are his 3 reasons:</p>\n\n<blockquote>\n  <ul>\n  <li>I\'ve seen a number of developers confused, not knowing whether to use <strong>string</strong> or <strong>String</strong> in their code. Because in C# the string (a keyword) maps exactly to System.String (an FCL type), there is no difference and either can be used.</li>\n  <li>In C#, <strong>long</strong> maps to <strong>System.Int64</strong>, but in a different programming language, <strong>long</strong> could map to an <strong>Int16</strong> or <strong>Int32</strong>. In fact, C++/CLI does in fact treat long as an <strong>Int32</strong>. Someone reading source code in one language could easily misinterpret the code\'s intention if he or she were used to programming in a different programming language. In fact, most languages won\'t even treat <strong>long</strong> as a keyword and won\'t compile code that uses it.</li>\n  <li>The FCL has many methods that have type names as part of their method names. For example, the <strong>BinaryReader</strong> type offers methods such as <strong>ReadBoolean</strong>, <strong>ReadInt32</strong>, <strong>ReadSingle</strong>, and so on, and the <strong>System.Convert</strong> type offers methods such as <strong>ToBoolean</strong>, <strong>ToInt32</strong>, <strong>ToSingle</strong>, and so on. Although it\'s legal to write the following code, the line with float feels very unnatural to me, and it\'s not obvious that the line is correct:</li>\n  </ul>\n</blockquote>\n\n<pre><code>BinaryReader br = new BinaryReader(...);\nfloat val  = br.ReadSingle(); // OK, but feels unnatural\nSingle val = br.ReadSingle(); // OK and feels good\n</code></pre>\n\n<p>So there you have it. I think these are all really good points. I however, don\'t find myself using Jeffrey\'s advice in my own code. Maybe I am too stuck in my C# world but I end up trying to make my code look like the framework code.</p>\n'}, {'answer_id': 15002, 'author': 'Mel', 'author_id': 1763, 'author_profile': 'https://Stackoverflow.com/users/1763', 'pm_score': 6, 'selected': False, 'text': '<p>It\'s a matter of convention, really.  <code>string</code> just looks more like C/C++ style.  The general convention is to use whatever shortcuts your chosen language has provided (int/Int for <code>Int32</code>).  This goes for "object" and <code>decimal</code> as well.</p>\n\n<p>Theoretically this could help to port code into some future 64-bit standard in which "int" might mean <code>Int64</code>, but that\'s not the point, and I would expect any upgrade wizard to change any <code>int</code> references to <code>Int32</code> anyway just to be safe.</p>\n'}, {'answer_id': 30797, 'author': 'user3296', 'author_id': 3296, 'author_profile': 'https://Stackoverflow.com/users/3296', 'pm_score': 9, 'selected': False, 'text': "<p><strong>There is one difference</strong> - you can't use <code>String</code> without <code>using System;</code> beforehand.</p>\n"}, {'answer_id': 42306, 'author': 'Anthony Mastrean', 'author_id': 3619, 'author_profile': 'https://Stackoverflow.com/users/3619', 'pm_score': 8, 'selected': False, 'text': '<p>\nI prefer the capitalized <code>.NET</code> types (rather than the aliases) for formatting reasons. The <code>.NET</code> types are colored the same as other object types (the value types are proper objects, after all).</p>\n\n<p>Conditional and control keywords (like <code>if</code>, <code>switch</code>, and <code>return</code>) are lowercase and colored dark blue (by default). And I would rather not have the disagreement in use and format.</p>\n\n<p>Consider:</p>\n\n<pre class="lang-c# prettyprint-override"><code>String someString; \nstring anotherString; \n</code></pre>\n'}, {'answer_id': 117035, 'author': 'Ishmael', 'author_id': 8930, 'author_profile': 'https://Stackoverflow.com/users/8930', 'pm_score': 7, 'selected': False, 'text': '<p>Using System types makes it easier to port between C# and VB.Net, if you are into that sort of thing.</p>\n'}, {'answer_id': 215263, 'author': 'TheSoftwareJedi', 'author_id': 18941, 'author_profile': 'https://Stackoverflow.com/users/18941', 'pm_score': 8, 'selected': False, 'text': '<p><code>string</code> and <code>String</code> are identical in all ways (except the uppercase "S").  There are no performance implications either way.</p>\n\n<p>Lowercase <code>string</code> is preferred in most projects due to the syntax highlighting</p>\n'}, {'answer_id': 215266, 'author': 'Hallgrim', 'author_id': 15454, 'author_profile': 'https://Stackoverflow.com/users/15454', 'pm_score': 7, 'selected': False, 'text': '<p><code>string</code> is just an alias for <code>System.String</code>. The compiler will treat them identically.</p>\n\n<p>The only practical difference is the syntax highlighting as you mention, and that you have to write <code>using System</code> if you use <code>String</code>.</p>\n'}, {'answer_id': 215304, 'author': 'artur02', 'author_id': 13937, 'author_profile': 'https://Stackoverflow.com/users/13937', 'pm_score': 10, 'selected': False, 'text': "<p><code>String</code> stands for <code>System.String</code> and it is a .NET Framework type. <strong><code>string</code> is an alias</strong> in the C# language for  <code>System.String</code>. Both of them are compiled to <strong><code>System.String</code> in IL</strong> (Intermediate Language), so there is no difference. Choose what you like and use that. If you code in C#, I'd prefer <code>string</code> as it's a C# type alias and well-known by C# programmers.</p>\n\n<p>I can say the same about <strong>(<code>int</code>, <code>System.Int32</code>)</strong> etc..</p>\n"}, {'answer_id': 215382, 'author': 'Pradeep Kumar Mishra', 'author_id': 22710, 'author_profile': 'https://Stackoverflow.com/users/22710', 'pm_score': 7, 'selected': False, 'text': '<p>Both are same. But from coding guidelines perspective it\'s better to use <code>string</code> instead of <code>String</code>. This is what generally developers use. e.g. instead of using <code>Int32</code> we use <code>int</code> as <code>int</code> is alias to <code>Int32</code></p>\n\n<p>FYI\n“The keyword string is simply an alias for the predefined class <code>System.String</code>.” - C# Language Specification 4.2.3\n<a href="http://msdn2.microsoft.com/En-US/library/aa691153.aspx" rel="noreferrer">http://msdn2.microsoft.com/En-US/library/aa691153.aspx</a></p>\n'}, {'answer_id': 215422, 'author': 'Jon Skeet', 'author_id': 22656, 'author_profile': 'https://Stackoverflow.com/users/22656', 'pm_score': 12, 'selected': False, 'text': '\n<p>Just for the sake of completeness, here\'s a brain dump of related information...</p>\n<p>As others have noted, <code>string</code> is an alias for <code>System.String</code>. Assuming your code using <code>String</code> compiles to <code>System.String</code> (i.e. you haven\'t got a using directive for some other namespace with a different <code>String</code> type), they compile to the same code, so at execution time there is no difference whatsoever. This is just one of the aliases in C#. The complete list is:</p>\n<pre class="lang-c# prettyprint-override"><code>object:  System.Object\nstring:  System.String\nbool:    System.Boolean\nbyte:    System.Byte\nsbyte:   System.SByte\nshort:   System.Int16\nushort:  System.UInt16\nint:     System.Int32\nuint:    System.UInt32\nlong:    System.Int64\nulong:   System.UInt64\nfloat:   System.Single\ndouble:  System.Double\ndecimal: System.Decimal\nchar:    System.Char\n</code></pre>\n<p>Apart from <code>string</code> and <code>object</code>, the aliases are all to value types. <code>decimal</code> is a value type, but not a primitive type in the CLR. The only primitive type which doesn\'t have an alias is <code>System.IntPtr</code>.</p>\n<p>In the spec, the value type aliases are known as &quot;simple types&quot;. Literals can be used for constant values of every simple type; no other value types have literal forms available. (Compare this with VB, which allows <code>DateTime</code> literals, and has an alias for it too.)</p>\n<p>There is one circumstance in which you <em>have</em> to use the aliases: when explicitly specifying an enum\'s underlying type. For instance:</p>\n<pre class="lang-c# prettyprint-override"><code>public enum Foo : UInt32 {} // Invalid\npublic enum Bar : uint   {} // Valid\n</code></pre>\n<p>That\'s just a matter of the way the spec defines enum declarations - the part after the colon has to be the <em>integral-type</em> production, which is one token of <code>sbyte</code>, <code>byte</code>, <code>short</code>, <code>ushort</code>, <code>int</code>, <code>uint</code>, <code>long</code>, <code>ulong</code>, <code>char</code>... as opposed to a <em>type</em> production as used by variable declarations for example. It doesn\'t indicate any other difference.</p>\n<p>Finally, when it comes to which to use: personally I use the aliases everywhere for the implementation, but the CLR type for any APIs. It really doesn\'t matter too much which you use in terms of implementation - consistency among your team is nice, but no-one else is going to care. On the other hand, it\'s genuinely important that if you refer to a type in an API, you do so in a language-neutral way. A method called <code>ReadInt32</code> is unambiguous, whereas a method called <code>ReadInt</code> requires interpretation. The caller could be using a language that defines an <code>int</code> alias for <code>Int16</code>, for example. The .NET framework designers have followed this pattern, good examples being in the <code>BitConverter</code>, <code>BinaryReader</code> and <code>Convert</code> classes.</p>\n'}, {'answer_id': 215813, 'author': 'TraumaPony', 'author_id': 18658, 'author_profile': 'https://Stackoverflow.com/users/18658', 'pm_score': 8, 'selected': False, 'text': "<p>It's been covered above; however, you can't use <code>string</code> in reflection; you must use <code>String</code>.</p>\n"}, {'answer_id': 215831, 'author': 'Lloyd Cotten', 'author_id': 21807, 'author_profile': 'https://Stackoverflow.com/users/21807', 'pm_score': 7, 'selected': False, 'text': "<p>As the others are saying, they're the same.  StyleCop rules, by default, will enforce you to use <code>string</code> as a C# code style best practice, except when referencing <code>System.String</code> static functions, such as <code>String.Format</code>, <code>String.Join</code>, <code>String.Concat</code>, etc...</p>\n"}, {'answer_id': 580546, 'author': 'Simon_Weaver', 'author_id': 16940, 'author_profile': 'https://Stackoverflow.com/users/16940', 'pm_score': 9, 'selected': False, 'text': "<p><code>string</code> is a reserved word, but <code>String</code> is just a class name. \nThis means that <code>string</code> cannot be used as a variable name by itself.</p>\n\n<p>If for some reason you wanted a variable called <em>string</em>, you'd see only the first of these compiles:</p>\n\n<pre><code>StringBuilder String = new StringBuilder();  // compiles\nStringBuilder string = new StringBuilder();  // doesn't compile \n</code></pre>\n\n<p>If you really want a variable name called <em>string</em> you can use <code>@</code> as a prefix:</p>\n\n<pre><code>StringBuilder @string = new StringBuilder();\n</code></pre>\n\n<p>Another critical difference: Stack Overflow highlights them differently. </p>\n"}, {'answer_id': 655907, 'author': 'Rasmus Faber', 'author_id': 5542, 'author_profile': 'https://Stackoverflow.com/users/5542', 'pm_score': 8, 'selected': False, 'text': '<p>C# is a language which is used together with the CLR.</p>\n\n<p><strong><code>string</code></strong> is a type in C#.</p>\n\n<p><strong><code>System.String</code></strong> is a type in the CLR.</p>\n\n<p>When you use C# together with the CLR <strong><code>string</code></strong> will be mapped to <strong><code>System.String</code></strong>.</p>\n\n<p>Theoretically, you could implement a C#-compiler that generated Java bytecode. A sensible implementation of this compiler would probably map <strong><code>string</code></strong> to <strong><code>java.lang.String</code></strong> in order to interoperate with the Java runtime library.</p>\n'}, {'answer_id': 4827000, 'author': 'claudioalpereira', 'author_id': 593614, 'author_profile': 'https://Stackoverflow.com/users/593614', 'pm_score': 6, 'selected': False, 'text': "<p>I'd just like to add this to lfousts answer, from Ritchers book:</p>\n\n<blockquote>\n  <p>The C# language specification states, “As a matter of style, use of the keyword is favored over\n  use of the complete system type name.” I disagree with the language specification; I prefer\n  to use the FCL type names and completely avoid the primitive type names. In fact, I wish that\n  compilers didn’t even offer the primitive type names and forced developers to use the FCL\n  type names instead. Here are my reasons:</p>\n  \n  <ul>\n  <li><p>I’ve seen a number of developers confused, not knowing whether to use <strong>string</strong>\n  or <strong>String</strong> in their code. Because in C# <strong>string</strong> (a keyword) maps exactly to\n  <strong>System.String</strong> (an FCL type), there is no difference and either can be used. Similarly,\n  I’ve heard some developers say that <strong>int</strong> represents a 32-bit integer when the application\n  is running on a 32-bit OS and that it represents a 64-bit integer when the application\n  is running on a 64-bit OS. This statement is absolutely false: in C#, an <strong>int</strong> always maps\n  to <strong>System.Int32</strong>, and therefore it represents a 32-bit integer regardless of the OS the\n  code is running on. If programmers would use <strong>Int32</strong> in their code, then this potential\n  confusion is also eliminated.</p></li>\n  <li><p>In C#, <strong>long</strong> maps to <strong>System.Int64</strong>, but in a different programming language, <strong>long</strong>\n  could map to an <strong>Int16</strong> or <strong>Int32</strong>. In fact, C++/CLI does treat <strong>long</strong> as an <strong>Int32</strong>.\n  Someone reading source code in one language could easily misinterpret the code’s\n  intention if he or she were used to programming in a different programming language.\n  In fact, most languages won’t even treat <strong>long</strong> as a keyword and won’t compile code\n  that uses it.</p></li>\n  <li><p>The FCL has many methods that have type names as part of their method names. For\n  example, the <strong>BinaryReader</strong> type offers methods such as <strong>ReadBoolean</strong>, <strong>ReadInt32</strong>,\n  <strong>ReadSingle</strong>, and so on, and the <strong>System.Convert</strong> type offers methods such as\n  <strong>ToBoolean</strong>, <strong>ToInt32</strong>, <strong>ToSingle</strong>, and so on. Although it’s legal to write the following\n  code, the line with <strong>float</strong> feels very unnatural to me, and it’s not obvious that the line is\n  correct:</p>\n\n<pre><code>BinaryReader br = new BinaryReader(...);\nfloat val = br.ReadSingle(); // OK, but feels unnatural\nSingle val = br.ReadSingle(); // OK and feels good\n</code></pre></li>\n  <li><p>Many programmers that use C# exclusively tend to forget that other programming\n  languages can be used against the CLR, and because of this, C#-isms creep into the\n  class library code. For example, Microsoft’s FCL is almost exclusively written in C# and\n  developers on the FCL team have now introduced methods into the library such as\n  <strong>Array</strong>’s <strong>GetLongLength</strong>, which returns an <strong>Int64</strong> value that is a <strong>long</strong> in C# but not\n  in other languages (like C++/CLI). Another example is <strong>System.Linq.Enumerable</strong>’s\n  <strong>LongCount</strong> method.</p></li>\n  </ul>\n</blockquote>\n\n<p>I didn't get his opinion before I read the complete paragraph.  </p>\n"}, {'answer_id': 5775710, 'author': 'user576533', 'author_id': 576533, 'author_profile': 'https://Stackoverflow.com/users/576533', 'pm_score': 6, 'selected': False, 'text': '<p><code>String</code> is not a keyword and it can be used as Identifier whereas <code>string</code> is a keyword and cannot be used as Identifier. And in function point of view both are same.</p>\n'}, {'answer_id': 6186799, 'author': 'RolandK', 'author_id': 558331, 'author_profile': 'https://Stackoverflow.com/users/558331', 'pm_score': 7, 'selected': False, 'text': '<p>Against what seems to be common practice among other programmers, I prefer <code>String</code> over <code>string</code>, just to highlight the fact that <code>String</code> is a reference type, as Jon Skeet mentioned.</p>\n'}, {'answer_id': 7173165, 'author': 'Dot NET', 'author_id': 856132, 'author_profile': 'https://Stackoverflow.com/users/856132', 'pm_score': 5, 'selected': False, 'text': "<p>There is no difference between the two - <code>string</code>, however, appears to be the preferred option when considering other developers' source code.</p>\n"}, {'answer_id': 7844012, 'author': 'JeeShen Lee', 'author_id': 440641, 'author_profile': 'https://Stackoverflow.com/users/440641', 'pm_score': 7, 'selected': False, 'text': '<p><code>string</code> is an alias (or shorthand) of <code>System.String</code>. That means, by typing <code>string</code> we meant <code>System.String</code>. You can read more in think link: <a href="http://www.jeeshenlee.com/2011/10/difference-between-string-and.html" rel="noreferrer">\'string\' is an alias/shorthand of System.String.</a></p>\n'}, {'answer_id': 8865991, 'author': 'Oded', 'author_id': 1583, 'author_profile': 'https://Stackoverflow.com/users/1583', 'pm_score': 6, 'selected': False, 'text': '<p>There is no difference.</p>\n\n<p>The C# keyword <code>string</code> maps to the .NET type <code>System.String</code> - it is an alias that keeps to the naming conventions of the language.</p>\n\n<p>Similarly, <code>int</code> maps to <code>System.Int32</code>.</p>\n'}, {'answer_id': 8866038, 'author': 'Joe Alfano', 'author_id': 1139127, 'author_profile': 'https://Stackoverflow.com/users/1139127', 'pm_score': 6, 'selected': False, 'text': '<p>String (<code>System.String</code>) is a class in the base class library. string (lower case) is a reserved work in C# that is an alias for System.String. Int32 vs int is a similar situation as is <code>Boolean vs. bool</code>. These C# language specific keywords enable you to declare primitives in a style similar to C. </p>\n'}, {'answer_id': 12112272, 'author': 'Michael Ray Lovett', 'author_id': 1106734, 'author_profile': 'https://Stackoverflow.com/users/1106734', 'pm_score': 6, 'selected': False, 'text': '<p>Coming late to the party: I use the CLR types 100% of the time (well, except if <em>forced</em> to use the C# type, but I don\'t remember when the last time that was). </p>\n\n<p>I originally started doing this years ago, as per the CLR books by Ritchie. It made sense to me that all CLR languages ultimately have to be able to support the set of CLR types, so using the CLR types yourself provided clearer, and possibly more "reusable" code.</p>\n\n<p>Now that I\'ve been doing it for years, it\'s a habit and I like the coloration that VS shows for the CLR types.</p>\n\n<p>The only real downer is that auto-complete uses the C# type, so I end up re-typing automatically generated types to specify the CLR type instead.</p>\n\n<p>Also, now, when I see "int" or "string", it just looks really wrong to me, like I\'m looking at 1970\'s C code.</p>\n'}, {'answer_id': 12706960, 'author': 'Zaid Masud', 'author_id': 374420, 'author_profile': 'https://Stackoverflow.com/users/374420', 'pm_score': 5, 'selected': False, 'text': '<p>One argument not mentioned elsewhere to prefer the pascal case <code>String</code>:</p>\n\n<p><code>System.String</code> is a reference type, and <em>reference types names are pascal case by convention</em>.</p>\n'}, {'answer_id': 12725425, 'author': 'Inverted Llama', 'author_id': 1250250, 'author_profile': 'https://Stackoverflow.com/users/1250250', 'pm_score': 4, 'selected': False, 'text': '<p><code>String</code> refers to a string object which comes with various functions for manipulating the contained string.</p>\n\n<p><code>string</code> refers to a primitive type </p>\n\n<p>In C# they both compile to String but in other languages they do not so you should use String if you want to deal with String objects and string if you want to deal with literals.</p>\n'}, {'answer_id': 12777808, 'author': 'Coder', 'author_id': 1696881, 'author_profile': 'https://Stackoverflow.com/users/1696881', 'pm_score': 5, 'selected': False, 'text': "<p>Yes, that's no difference between them, just like the <code>bool</code> and <code>Boolean</code>.</p>\n"}, {'answer_id': 19729734, 'author': 'user2771704', 'author_id': 2771704, 'author_profile': 'https://Stackoverflow.com/users/2771704', 'pm_score': 6, 'selected': False, 'text': '<p>There\'s a quote on this issue from <a href="https://www.goodreads.com/book/show/14975275-illustrated-c-2012" rel="noreferrer">Daniel Solis\' book</a>.</p>\n\n<blockquote>\n  <p>All the predefined types  are mapped directly to\n  underlying .NET types. The C# type names (string) are simply aliases for the\n  .NET types (String or System.String), so using the .NET names works fine syntactically, although\n  this is discouraged. Within a C# program, you should use the C# names\n  rather than the .NET names.</p>\n</blockquote>\n'}, {'answer_id': 21144988, 'author': 'Shivprasad Koirala', 'author_id': 993672, 'author_profile': 'https://Stackoverflow.com/users/993672', 'pm_score': 8, 'selected': False, 'text': '<p><a href="http://www.youtube.com/watch?v=ikqUUIg8gmk" rel="noreferrer">This YouTube</a> video demonstrates practically how they differ.</p>\n<p>But now for a long textual answer.</p>\n<p>When we talk about <code>.NET</code> there are two different things one there is <code>.NET</code> framework and the other there are languages (<code>C#</code>, <code>VB.NET</code> etc) which use that framework.</p>\n<p><img src="https://i.stack.imgur.com/jQUcj.png" alt="enter image description here" /></p>\n<p>&quot;<code>System.String</code>&quot; a.k.a &quot;String&quot; (capital &quot;S&quot;) is a <code>.NET</code> framework data type while &quot;string&quot; is a <code>C#</code> data type.</p>\n<p><img src="https://i.stack.imgur.com/tKhjh.png" alt="enter image description here" /></p>\n<p>In short &quot;String&quot; is an alias (the same thing called with different names) of &quot;string&quot;. So technically both the below code statements will give the same output.</p>\n<pre><code>String s = &quot;I am String&quot;;\n</code></pre>\n<p>or</p>\n<pre><code>string s = &quot;I am String&quot;;\n</code></pre>\n<p>In the same way, there are aliases for other C# data types as shown below:</p>\n<p>object: <code>System.Object</code>, string: <code>System.String</code>, bool: <code>System.Boolean</code>, byte: <code>System.Byte</code>, sbyte: <code>System.SByte</code>, short: <code>System.Int16</code> and so on.</p>\n<p><strong>Now the million-dollar question from programmer\'s point of view: So when to use &quot;String&quot; and &quot;string&quot;?</strong></p>\n<p>The first thing to avoid confusion use one of them consistently. But from best practices perspective when you do variable declaration it\'s good to use &quot;string&quot; (small &quot;s&quot;) and when you are using it as a class name then &quot;String&quot; (capital &quot;S&quot;) is preferred.</p>\n<p>In the below code the left-hand side is a variable declaration and it is declared using &quot;string&quot;. On the right-hand side, we are calling a method so &quot;String&quot; is more sensible.</p>\n<pre><code>string s = String.ToUpper() ;\n</code></pre>\n'}, {'answer_id': 22250985, 'author': 'zap92', 'author_id': 3275405, 'author_profile': 'https://Stackoverflow.com/users/3275405', 'pm_score': 5, 'selected': False, 'text': '<p>There is practically no difference</p>\n\n<p>The C# keyword string maps to the .NET type System.String - it is an alias that keeps to the naming conventions of the language.</p>\n'}, {'answer_id': 23762744, 'author': 'Geeky Ninja', 'author_id': 2674680, 'author_profile': 'https://Stackoverflow.com/users/2674680', 'pm_score': 3, 'selected': False, 'text': '<p><strong>String:</strong> A String object is called immutable (read-only) because its value cannot be modified once it has been created. Methods that appear to modify a String object actually return a new String object that contains the modification. If it is necessary to modify the actual contents of a string-like object</p>\n\n<p><strong>string:</strong> The string type represents a sequence of zero or more Unicode characters. string is an alias for String in the .NET Framework. <code>string</code> is the intrinsic C# datatype, and is an alias for the system provided type "System.String". The C# specification states that as a matter of style the keyword (<strong>string</strong>) is preferred over the full system type name (System.String, or String).\nAlthough string is a reference type, the equality operators (== and !=) are defined to compare the values of string objects, not references. This makes testing for string equality more intuitive. For example: </p>\n\n<p><strong>Difference between string &amp; String:</strong></p>\n\n<ul>\n<li>The <code>string</code> is usually used for declaration while <code>String</code> is used for accessing static string methods</li>\n<li>You can use <code>\'string\'</code> do declare fields, properties etc that use the predefined type <code>\'string\'</code>, since the C# specification tells me this is good style.</li>\n<li>You can use <code>\'String\'</code> to use system-defined methods, such as String.Compare etc. They are originally defined on \'System.String\', not \'string\'. <code>\'string\'</code> is just an alias in this case.</li>\n<li>You can also use <code>\'String\'</code> or \'System.Int32\' when communicating with other system, especially if they are CLR-compliant. i.e. - if I get data from elsewhere, I\'d de-serialize it into a System.Int32 rather than an \'int\', if the origin by definition was something else than a C# system.</li>\n</ul>\n'}, {'answer_id': 24155226, 'author': 'Neel', 'author_id': 1997103, 'author_profile': 'https://Stackoverflow.com/users/1997103', 'pm_score': 5, 'selected': False, 'text': '<p><strong>string</strong> is a keyword, and you can\'t use string as an identifier. </p>\n\n<p><strong>String</strong> is not a keyword, and you can use it as an identifier:</p>\n\n<p><strong>Example</strong></p>\n\n<pre><code>string String = "I am a string";\n</code></pre>\n\n<p>The keyword <code>string</code>  is an alias for\n <code>System.String</code> aside from the keyword issue, the two are exactly\n equivalent.</p>\n\n<pre><code> typeof(string) == typeof(String) == typeof(System.String)\n</code></pre>\n'}, {'answer_id': 24161540, 'author': 'Vijay Singh Rana', 'author_id': 1537055, 'author_profile': 'https://Stackoverflow.com/users/1537055', 'pm_score': 3, 'selected': False, 'text': '<p>string is an alias for <a href="http://msdn.microsoft.com/en-us/library/system.string.aspx" rel="noreferrer">String</a> in the .NET Framework.</p>\n\n<p>Where "String" is in fact <code>System.String.</code></p>\n\n<p>I would say that they are interchangeable and there is no difference when and where you should use one or the other.</p>\n\n<p>It would be better to be consistent with which one you did use though.</p>\n\n<p>For what it\'s worth, I use <code>string</code> to declare types - variables, properties, return values and parameters. This is consistent with the use of other system types - <code>int, bool, var</code> etc (although <code>Int32</code> and <code>Boolean</code> are also correct).</p>\n\n<p>I use String when using the static methods on the String class, like <code>String.Split()</code> or <code>String.IsNullOrEmpty()</code>. I feel that this makes more sense because the methods belong to a class, and it is consistent with how I use other static methods.</p>\n'}, {'answer_id': 24319676, 'author': 'Kalu Singh Rao', 'author_id': 3674931, 'author_profile': 'https://Stackoverflow.com/users/3674931', 'pm_score': 3, 'selected': False, 'text': '<p>As far as I know, <code>string</code> is just an alias for <code>System.String</code>, and similar aliases exist for <code>bool</code>, <code>object</code>, <code>int</code>... the only subtle difference is that you can use <code>string</code> without a "using <code>System;</code>" directive, while String requires it (otherwise you should specify <code>System.String</code> in full).</p>\n\n<p>About which is the best to use, I guess it\'s a matter of taste. Personally I prefer <code>string</code>, but I it\'s not a religious issue.</p>\n'}, {'answer_id': 24972696, 'author': 'InfZero', 'author_id': 379371, 'author_profile': 'https://Stackoverflow.com/users/379371', 'pm_score': 3, 'selected': False, 'text': '<p>In the context of <strong>MSDN Documentation</strong>, <code>String</code> class is documented like any other data type (<em>e.g.</em>, <code>XmlReader</code>, <code>StreamReader</code>) in the <strong><a href="http://msdn.microsoft.com/en-us/library/system.string%28v=vs.110%29.aspx" rel="noreferrer">BCL</a></strong>.</p>\n\n<p>And <code>string</code> is documented like a keyword (C# Reference) or like any basic C# language construct (<em>e.g.</em>, <code>for</code>, <code>while</code>, <code>default</code>).</p>\n\n<p><strong><a href="http://msdn.microsoft.com/en-us/library/362314fe.aspx" rel="noreferrer">Reference</a></strong>.</p>\n'}, {'answer_id': 27706582, 'author': 'Teter28', 'author_id': 3545103, 'author_profile': 'https://Stackoverflow.com/users/3545103', 'pm_score': 4, 'selected': False, 'text': '<p>You don\'t need <strong>import</strong> namespace (using <code>System</code>;) to use <code>string</code> because it is a global alias of <code>System.String</code>.</p>\n\n<p>To know more about aliases you can check this <a href="https://www.codeproject.com/Articles/11856/C-Aliases" rel="noreferrer">link</a>.</p>\n'}, {'answer_id': 27965515, 'author': 'Jeppe Stig Nielsen', 'author_id': 1336654, 'author_profile': 'https://Stackoverflow.com/users/1336654', 'pm_score': 7, 'selected': False, 'text': '<p>New answer after 6 years and 5 months (procrastination).</p>\n\n<p>While <code>string</code> is a reserved C# keyword that always has a fixed meaning, <code>String</code> is just an ordinary <em>identifier</em> which could refer to anything. Depending on members of the current type, the current namespace and the applied <code>using</code> directives and their placement, <code>String</code> could be a value or a type distinct from <code>global::System.String</code>.</p>\n\n<p>I shall provide two examples where <em><code>using</code> directives will not help</em>.</p>\n\n<hr>\n\n<p>First, when <code>String</code> is a <strong><em>value</em></strong> of the current type (or a local variable):</p>\n\n<pre><code>class MySequence&lt;TElement&gt;\n{\n  public IEnumerable&lt;TElement&gt; String { get; set; }\n\n  void Example()\n  {\n    var test = String.Format("Hello {0}.", DateTime.Today.DayOfWeek);\n  }\n}\n</code></pre>\n\n<p>The above will not compile because <code>IEnumerable&lt;&gt;</code> does not have a non-static member called <code>Format</code>, and no extension methods apply. In the above case, it may still be possible to use <code>String</code> in other contexts where a <em>type</em> is the only possibility syntactically. For example <code>String local = "Hi mum!";</code> could be OK (depending on namespace and <code>using</code> directives).</p>\n\n<p>Worse: Saying <code>String.Concat(someSequence)</code> will likely (depending on <code>using</code>s) go to the Linq extension method <code>Enumerable.Concat</code>. It will not go to the static method <code>string.Concat</code>.</p>\n\n<hr>\n\n<p>Secondly, when <code>String</code> is another <strong><em>type</em></strong>, nested inside the current type:</p>\n\n<pre><code>class MyPiano\n{\n  protected class String\n  {\n  }\n\n  void Example()\n  {\n    var test1 = String.Format("Hello {0}.", DateTime.Today.DayOfWeek);\n    String test2 = "Goodbye";\n  }\n}\n</code></pre>\n\n<p>Neither statement in the <code>Example</code> method compiles. Here <code>String</code> is always a piano <a href="http://en.wikipedia.org/wiki/String_(music)" rel="noreferrer">string</a>, <code>MyPiano.String</code>. No member (<code>static</code> or not) <code>Format</code> exists on it (or is inherited from its base class). And the value <code>"Goodbye"</code> cannot be converted into it.</p>\n'}, {'answer_id': 29489427, 'author': 'Anuja Lamahewa', 'author_id': 4298321, 'author_profile': 'https://Stackoverflow.com/users/4298321', 'pm_score': 5, 'selected': False, 'text': '<p>Both are the same.The difference is how you use it.\nConvention is,</p>\n\n<p><strong>s</strong>tring is for variables </p>\n\n<p><strong>S</strong>tring is for calling other String class methods</p>\n\n<p>Like:</p>\n\n<pre><code>string fName = "John";\nstring lName = "Smith";\n\nstring fullName = String.Concat(fName,lName);\n\nif (String.IsNullOrEmpty(fName))\n{\n  Console.WriteLine("Enter first name");\n}\n</code></pre>\n'}, {'answer_id': 32893650, 'author': 'tic', 'author_id': 1898688, 'author_profile': 'https://Stackoverflow.com/users/1898688', 'pm_score': 4, 'selected': False, 'text': '<p>In case it\'s useful to really see there is no difference between <code>string</code> and <code>System.String</code>:</p>\n\n<pre><code>var method1 = typeof(MyClass).GetMethod("TestString1").GetMethodBody().GetILAsByteArray();\nvar method2 = typeof(MyClass).GetMethod("TestString2").GetMethodBody().GetILAsByteArray();\n\n//...\n\npublic string TestString1()\n{\n    string str = "Hello World!";\n    return str;\n}\n\npublic string TestString2()\n{\n    String str = "Hello World!";\n    return str;\n}\n</code></pre>\n\n<p>Both produce exactly the same IL byte array:</p>\n\n<pre><code>[ 0, 114, 107, 0, 0, 112, 10, 6, 11, 43, 0, 7, 42 ]\n</code></pre>\n'}, {'answer_id': 34490521, 'author': 'yazan_ati', 'author_id': 5644664, 'author_profile': 'https://Stackoverflow.com/users/5644664', 'pm_score': 3, 'selected': False, 'text': "<p>As pointed out, they are the same thing and <code>string</code> is just an alias to <code>String</code>.</p>\n\n<p>For what it's worth, I use string to declare types - variables, properties, return values and parameters. This is consistent with the use of other system types - <code>int, bool, var</code> etc (although <code>Int32</code> and <code>Boolean</code> are also correct).</p>\n\n<p>I use <code>String</code> when using the static methods on the String class, like <code>String.Split()</code> or <code>String.IsNullOrEmpty()</code>. I feel that this makes more sense because the methods belong to a class, and it is consistent with how I use other static methods.</p>\n"}, {'answer_id': 34898005, 'author': 'Pritam Jyoti Ray', 'author_id': 1324573, 'author_profile': 'https://Stackoverflow.com/users/1324573', 'pm_score': 3, 'selected': False, 'text': '<p>There is no difference between the two.  You can use either of them in your code.</p>\n\n<p><code>System.String</code> is a class (reference type) defined the <code>mscorlib</code> in the namespace <code>System</code>. In other words, <code>System.String</code> is a type in the <code>CLR</code>.</p>\n\n<p><code>string</code> is a keyword in <code>C#</code></p>\n'}, {'answer_id': 37629561, 'author': 'hubot', 'author_id': 4598557, 'author_profile': 'https://Stackoverflow.com/users/4598557', 'pm_score': 4, 'selected': False, 'text': "<p>To be honest, in practice usually there is not difference between <code>System.String</code> and <code>string</code>.</p>\n<p>All types in C# are objects and all derives from <code>System.Object</code> class. One difference is that string is a C# keyword and <code>String</code> you can use as variable name. <code>System.String</code> is conventional .NET name of this type and string is convenient C# name. Here is simple program which presents difference between <code>System.String</code> and string.</p>\n<pre><code>string a = new string(new char[] { 'x', 'y', 'z' });\nstring b = new String(new char[] { 'x', 'y', 'z' });\nString c = new string(new char[] { 'x', 'y', 'z' });\nString d = new String(new char[] { 'x', 'y', 'z' });\nMessageBox.Show((a.GetType() == typeof(String) &amp;&amp; a.GetType() == typeof(string)).ToString()); // shows true\nMessageBox.Show((b.GetType() == typeof(String) &amp;&amp; b.GetType() == typeof(string)).ToString()); // shows true\nMessageBox.Show((c.GetType() == typeof(String) &amp;&amp; c.GetType() == typeof(string)).ToString()); // shows true\nMessageBox.Show((d.GetType() == typeof(String) &amp;&amp; d.GetType() == typeof(string)).ToString()); // shows true\n</code></pre>\n<p>@JonSkeet in my compiler</p>\n<pre><code>public enum Foo : UInt32 { }\n</code></pre>\n<p>is working. I've Visual Studio 2015 Community.</p>\n"}, {'answer_id': 41081848, 'author': 'sayah imad', 'author_id': 5223540, 'author_profile': 'https://Stackoverflow.com/users/5223540', 'pm_score': 3, 'selected': False, 'text': "<p><strong>String</strong> : Represent a class</p>\n\n<p><strong>string</strong> : Represent an alias</p>\n\n<blockquote>\n  <p>It's just a coding convention from microsoft .</p>\n</blockquote>\n"}, {'answer_id': 43012741, 'author': 'Saurabh', 'author_id': 3556867, 'author_profile': 'https://Stackoverflow.com/users/3556867', 'pm_score': 3, 'selected': False, 'text': '<p><code>string</code> is equal to <code>System.String</code> in VS2015 if you write this:</p>\n<pre><code>System.String str;\n</code></pre>\n<p>Than compiler will show potential fix to optimize it and after applying that fixe it will look like this</p>\n<pre><code>string str;\n</code></pre>\n'}, {'answer_id': 46813546, 'author': 'DavidWainwright', 'author_id': 385638, 'author_profile': 'https://Stackoverflow.com/users/385638', 'pm_score': 3, 'selected': False, 'text': "<p>I prefer to use <code>string</code> because this type is used so much that I don't want the syntax highlighter blending it in with all the other classes. Although it is a class it is used more like a primitive therefore I think the different highlight colour is appropriate.</p>\n\n<p>If you right click on the <code>string</code> keyword and select <code>Go to definition</code> from the context menu it'll take you to the <code>String</code> class - it's just syntactic sugar but it improves readability imo.</p>\n"}, {'answer_id': 47221903, 'author': 'Jineesh Uvantavida', 'author_id': 2459039, 'author_profile': 'https://Stackoverflow.com/users/2459039', 'pm_score': 3, 'selected': False, 'text': '<p>A <strong>string</strong> is a <em>sequential collection of characters</em> that is used to represent text.</p>\n\n<p>A <strong>String object</strong> is a <em>sequential collection of System.Char objects</em> that represent a string; a System.Char object corresponds to a UTF-16 code unit.</p>\n\n<p>The value of the String object is the content of the sequential collection of System.Char objects, and that value is immutable (that is, it is read-only). </p>\n\n<p>For more information about the immutability of strings, see the Immutability and the StringBuilder class section in msdn. </p>\n\n<p>The maximum size of a String object in memory is 2GB, or about 1 billion characters.</p>\n\n<p>Note : answer is extracted from msdn help section. You can see the full content <a href="https://msdn.microsoft.com/en-us/library/system.string(v=vs.110).aspx" rel="noreferrer">here in msdn String Class</a> topic under Remarks section</p>\n'}, {'answer_id': 48120399, 'author': 'Taslim Oseni', 'author_id': 5670752, 'author_profile': 'https://Stackoverflow.com/users/5670752', 'pm_score': 4, 'selected': False, 'text': "<p>In C#, string is the shorthand version of System.String (String). They basically mean the same thing.</p>\n<p>It's just like <code>bool</code> and <code>Boolean</code>, not much difference..</p>\n"}, {'answer_id': 48223011, 'author': 'Hasan Jafarov', 'author_id': 2806548, 'author_profile': 'https://Stackoverflow.com/users/2806548', 'pm_score': 3, 'selected': False, 'text': '<p><code>string</code> is short name of <a href="https://msdn.microsoft.com/en-us/library/system.string(v=vs.110).aspx" rel="noreferrer"><code>System.String</code></a>. \n<code>String</code> or <code>System.String</code> is name of string in <code>CTS(Common Type System)</code>.</p>\n'}, {'answer_id': 48322758, 'author': 'BanksySan', 'author_id': 442351, 'author_profile': 'https://Stackoverflow.com/users/442351', 'pm_score': 5, 'selected': False, 'text': '<p>There is one practical difference between <code>string</code> and <code>String</code>.</p>\n\n<pre><code>nameof(String); // compiles\nnameof(string); // doesn\'t compile\n</code></pre>\n\n<p>This is because <code>string</code> is a keyword (an alias in this case) whereas <code>String</code> is a type.</p>\n\n<p>The same is true for the other aliases as well.</p>\n\n<pre class="lang-none prettyprint-override"><code>| Alias     | Type             |\n|-----------|------------------|\n|  bool     |  System.Boolean  |\n|  byte     |  System.Byte     |\n|  sbyte    |  System.SByte    |\n|  char     |  System.Char     |\n|  decimal  |  System.Decimal  |\n|  double   |  System.Double   |\n|  float    |  System.Single   |\n|  int      |  System.Int32    |\n|  uint     |  System.UInt32   |\n|  long     |  System.Int64    |\n|  ulong    |  System.UInt64   |\n|  object   |  System.Object   |\n|  short    |  System.Int16    |\n|  ushort   |  System.UInt16   |\n|  string   |  System.String   |\n</code></pre>\n'}, {'answer_id': 48563657, 'author': 'v.slobodzian', 'author_id': 9205802, 'author_profile': 'https://Stackoverflow.com/users/9205802', 'pm_score': 3, 'selected': False, 'text': '<p>Jeffrey Richter written:</p>\n\n<blockquote>\n  <p>Another way to think of this is that the C# compiler automatically\n  assumes that you have the following <code>using</code> directives in all of your\n  source code files:</p>\n</blockquote>\n\n<pre><code>using int = System.Int32;\nusing uint = System.UInt32;\nusing string = System.String;\n...\n</code></pre>\n\n<blockquote>\n  <p>I’ve seen a number of developers confused, not knowing whether to use\n  string or String in their code. Because in C# string (a keyword) maps\n  exactly to System.String (an FCL type), <strong>there is no difference</strong> and\n  either can be used.</p>\n</blockquote>\n'}, {'answer_id': 48680864, 'author': 'wild coder', 'author_id': 9106094, 'author_profile': 'https://Stackoverflow.com/users/9106094', 'pm_score': 4, 'selected': False, 'text': '<p>First of All, both <code>string</code> &amp; <code>String</code> are not same.\nThere is a difference:\n<code>String</code> is not a keyword and it can be used as an identifier whereas <code>string</code> is a keyword and cannot be used as identifier.</p>\n<p>I am trying to explain with different example :\nFirst, when I put <code>string s;</code>  into Visual Studio and hover over it I get (without the colour):<br />\n<a href="https://i.stack.imgur.com/wHzSk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wHzSk.jpg" alt="String Definition" /></a></p>\n<p>That says that string is <code>System.String</code>, right?\nThe documentation is at <a href="https://msdn.microsoft.com/en-us/library/362314fe.aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/362314fe.aspx</a>. The second sentence says &quot;string is an alias for String in the .NET Framework.&quot;.</p>\n'}, {'answer_id': 51296196, 'author': 'Jaider', 'author_id': 480700, 'author_profile': 'https://Stackoverflow.com/users/480700', 'pm_score': 3, 'selected': False, 'text': '<p>As you already know <code>string</code> is just alias for <code>System.String</code>. But what should I use? it just personal preference.</p>\n\n<p>In my case, I love to use <code>string</code> rather than use <code>System.String</code> because <code>String</code> requires a namespace <code>using System;</code> or a full name <code>System.String</code>. </p>\n\n<p>So I believe the alias  <code>string</code> was created for simplicity and I love it!</p>\n'}, {'answer_id': 51467104, 'author': 'Just Fair', 'author_id': 8207463, 'author_profile': 'https://Stackoverflow.com/users/8207463', 'pm_score': 3, 'selected': False, 'text': '<p>string is a shortcut for <code>System.String</code>. The only difference is that you don´t need to reference to <code>System.String</code> namespace. So would be better using string than String. </p>\n'}, {'answer_id': 52841014, 'author': 'Burak Yeniçeri', 'author_id': 9131762, 'author_profile': 'https://Stackoverflow.com/users/9131762', 'pm_score': 3, 'selected': False, 'text': "<p><code>String</code> is the class of <code>string</code>. If you remove <code>System</code> namespace from using statements, you can see that <code>String</code> has gone but <code>string</code> is still here. <code>string</code> is keyword for String. Like<br>\n <code>int and Int32<br>\nshort and Int16<br>\nlong and Int64</code><br>\n   So the keywords are just some words that uses a class. These keywords are specified by C#(so Microsoft, because C# is Microsoft's). Briefly, there's no difference. Using <code>string or String</code>. That doesn't matter. They are same.</p>\n"}, {'answer_id': 53573427, 'author': 'Braham Prakash Yadav', 'author_id': 10714818, 'author_profile': 'https://Stackoverflow.com/users/10714818', 'pm_score': 3, 'selected': False, 'text': '<p>it is common practice to declare a variable using C# keywords.\nIn fact, every C# type has an equivalent in .NET. As another example, short and int in C# map to Int16 and Int32 in .NET. So, technically there is no difference between string and String, but \nIn C#, string is an alias for the String class in .NET framework. </p>\n'}, {'answer_id': 55628158, 'author': 'aloisdg', 'author_id': 1248177, 'author_profile': 'https://Stackoverflow.com/users/1248177', 'pm_score': 6, 'selected': False, 'text': '<p><a href="https://stackoverflow.com/users/23283/jaredpar">@JaredPar</a> (a developer on the C# compiler and prolific SO user!) wrote a <a href="http://blog.paranoidcoding.com/2019/04/08/string-vs-String-is-not-about-style.html" rel="noreferrer">great blog post</a> on this issue. I think it is worth sharing here. It is a nice perspective on our subject.</p>\n<blockquote>\n<h1><code>string</code> vs. <code>String</code> is not a style debate</h1>\n</blockquote>\n<blockquote>\n<p>[...]</p>\n</blockquote>\n<blockquote>\n<p>The keyword <code>string</code> has concrete meaning in C#. It is the type <code>System.String</code> which exists in the core runtime assembly. The runtime intrinsically understands this type and provides the capabilities developers expect for strings in .NET. Its presence is so critical to C# that if that type doesn’t exist the compiler will exit before attempting to even parse a line of code. Hence <code>string</code> has a precise, unambiguous meaning in C# code.</p>\n</blockquote>\n<blockquote>\n<p>The identifier <code>String</code> though has no concrete meaning in C#. It is an identifier that goes through all the name lookup rules as <code>Widget</code>, <code>Student</code>, etc … It could bind to string or it could bind to a type in another assembly entirely whose purposes may be entirely different than <code>string</code>. Worse it could be defined in a way such that code like <code>String s = &quot;hello&quot;</code>; continued to compile.</p>\n</blockquote>\n<blockquote>\n<pre><code>class TricksterString { \n  void Example() {\n    String s = &quot;Hello World&quot;; // Okay but probably not what you expect.\n  }\n}\n\nclass String {\n  public static implicit operator String(string s) =&gt; null;\n}\n</code></pre>\n<p>The actual meaning of <code>String</code> will always depend on name resolution.\nThat means it depends on all the source files in the project and all\nthe types defined in all the referenced assemblies. In short it\nrequires quite a bit of context to <em>know</em> what it means.</p>\n<p>True that in the vast majority of cases <code>String</code> and <code>string</code> will bind to\nthe same type. But using <code>String</code> still means developers are leaving\ntheir program up to interpretation in places where there is only one\ncorrect answer. When <code>String</code> does bind to the wrong type it can leave\ndevelopers debugging for hours, filing bugs on the compiler team, and\ngenerally wasting time that could’ve been saved by using <code>string</code>.</p>\n<p>Another way to visualize the difference is with this sample:</p>\n<pre><code>string s1 = 42; // Errors 100% of the time  \nString s2 = 42; // Might error, might not, depends on the code\n</code></pre>\n<p>Many will argue that while this is information technically accurate using <code>String</code> is still fine because it’s exceedingly rare that a codebase would define a type of this name. Or that when <code>String</code> is defined it’s a sign of a bad codebase.</p>\n</blockquote>\n<blockquote>\n<p>[...]</p>\n</blockquote>\n<blockquote>\n<p>You’ll see that <code>String</code> is defined for a number of completely valid purposes: reflection helpers, serialization libraries, lexers, protocols, etc … For any of these libraries <code>String</code> vs. <code>string</code> has real consequences depending on where the code is used.</p>\n</blockquote>\n<blockquote>\n<p>So remember when you see the <code>String</code> vs. <code>string</code> debate this is about semantics, not style. Choosing string gives crisp meaning to your codebase. Choosing <code>String</code> isn’t wrong but it’s leaving the door open for surprises in the future.</p>\n</blockquote>\n<p>Note: I copy/pasted most of the blog posts for archive reasons. I ignore some parts, so I recommend skipping and reading the <a href="http://blog.paranoidcoding.com/2019/04/08/string-vs-String-is-not-about-style.html" rel="noreferrer">blog post</a> if you can.</p>\n'}, {'answer_id': 56133714, 'author': 'Gonçalo Garrido', 'author_id': 11312923, 'author_profile': 'https://Stackoverflow.com/users/11312923', 'pm_score': 3, 'selected': False, 'text': '<p>declare a string variable with string but use the String class when accessing one of its static members:</p>\n\n<pre><code>String.Format()\n</code></pre>\n\n<p>Variable </p>\n\n<pre><code>string name = "";\n</code></pre>\n'}, {'answer_id': 56753700, 'author': 'Ted Mucuzany', 'author_id': 11652382, 'author_profile': 'https://Stackoverflow.com/users/11652382', 'pm_score': 3, 'selected': False, 'text': '<p>All the above is basically correct. One can check it. Just write a short method</p>\n\n<pre><code>public static void Main()\n{\n    var s = "a string";\n}\n</code></pre>\n\n<p>compile it and open <code>.exe</code> with <code>ildasm</code> to see</p>\n\n<pre><code>.method private hidebysig static void  Main(string[] args) cil managed\n{\n  .entrypoint\n  // Code size       8 (0x8)\n  .maxstack  1\n  .locals init ([0] string s)\n  IL_0000:  nop\n  IL_0001:  ldstr      "a string"\n  IL_0006:  stloc.0\n  IL_0007:  ret\n} // end of method Program::Main\n</code></pre>\n\n<p>then change <code>var</code> to <code>string</code> and <code>String</code>, compile, open with <code>ildasm</code> and see <code>IL</code> does not change. It also shows the creators of the language prefer just <code>string</code> when difining variables (spoiler: when calling members they prefer <code>String</code>).</p>\n'}, {'answer_id': 56846041, 'author': 'Ali Sufyan', 'author_id': 10943076, 'author_profile': 'https://Stackoverflow.com/users/10943076', 'pm_score': 2, 'selected': False, 'text': '<p>Image result for string vs String <a href="http://www.javatpoint.com" rel="nofollow noreferrer">www.javatpoint.com</a> \nIn C#, <code>string</code> is an alias for the <code>String</code> class in .NET framework. In fact, every C# type has an equivalent in .NET.<br/> <strong>Another little difference</strong> is that if you use the <code>String</code> class, you need to import the <code>System</code> namespace, whereas you don\'t have to import namespace when using the <code>string</code> keyword</p>\n'}, {'answer_id': 57526143, 'author': 'MicroservicesOnDDD', 'author_id': 7760271, 'author_profile': 'https://Stackoverflow.com/users/7760271', 'pm_score': 2, 'selected': False, 'text': '<p>There are many (e.g. Jeffrey Richter in his book <a href="https://stackoverflow.com/questions/7074/what-is-the-difference-between-string-and-string-in-c/12863#12863">CLR Via C#</a>) who are saying that there is no difference between <code>System.String</code> and <code>string</code>, and also <code>System.Int32</code> and <code>int</code>, but we must discriminate a little deeper to really squeeze the juice out of this question so we can get all the nutritional value out of it (write better code).</p>\n\n<p>A. They are the Same...</p>\n\n<ol>\n<li>to the compiler.</li>\n<li>to the developer. (We know #1 and eventually achieve autopilot.)</li>\n</ol>\n\n<p>B. They are Different in Famework and in Non-C# Contexts. Different...</p>\n\n<ol>\n<li>to OTHER languages that are NOT C#</li>\n<li>in an optimized CIL (was MSIL) context (the .NET VM assembly language)</li>\n<li>in a platform-targeted context -- the .NET Framework or Mono or any CIL-type area</li>\n<li>in a book targeting multiple .NET Languages (such as VB.NET, F#, etc.)</li>\n</ol>\n\n<p>So, the true answer is that it is only because C# has to co-own the .NET space with other languages that this question even exists.</p>\n\n<p>C. To Summarize...</p>\n\n<p>You use <code>string</code> and <code>int</code> and the other C# types in a C#-only targeted audience (ask the question, who is going to read this code, or use this library). For your internal company, if you only use C#, then stick to the C# types.</p>\n\n<p>...and you use <code>System.String</code> and <code>System.Int32</code> in a multilingual or framework targeted audience (when C# is not the only audience). For your internal organization, if you also use VB.NET or F# or any other .NET language, or develop libraries for consumption by customers who may, then you should use the "Frameworky" types in those contexts so that everyone can understand your interface, no matter what universe they are from. (What is Klingon for <code>System.String</code>, anyway?)</p>\n\n<p>HTH.</p>\n'}, {'answer_id': 66428994, 'author': 'TRK', 'author_id': 11652409, 'author_profile': 'https://Stackoverflow.com/users/11652409', 'pm_score': 2, 'selected': False, 'text': '<p>There is no major difference between <code>string</code> and <code>String</code> in C#.</p>\n<p><code>String</code> is a class in the .NET framework in the System namespace. The fully qualified name is <code>System.String</code>. The lower case string is an alias of <code>System.String</code>.</p>\n<p>But its recommended to use <code>string</code> while declaring variables like:</p>\n<pre><code>string str = &quot;Hello&quot;;\n</code></pre>\n<p>And we can use <code>String</code> while using any built-in method for strings like <code>String.IsNullOrEmpty()</code>.</p>\n<p>Also one difference between these two is like before using <code>String</code> we have to import system namespace in cs file and <code>string</code> can be used directly.</p>\n'}, {'answer_id': 70405501, 'author': 'Ran Turner', 'author_id': 7494218, 'author_profile': 'https://Stackoverflow.com/users/7494218', 'pm_score': 2, 'selected': False, 'text': "<p>Essentially, <strong>there is no difference between</strong> <code>string</code> and <code>String</code> in C#.</p>\n<p><code>String</code> is a class in the .NET framework in the System namespace under <code>System.String</code>, Whereas, lower case <code>string</code> is an alias of <code>System.String</code>.</p>\n<p>Logging the full name of both types can prove this</p>\n<pre><code>string s1= &quot;hello there 1&quot;;\nString s2 = &quot;hello there 2&quot;;\n        \nConsole.WriteLine(s1.GetType().FullName); // System.String\nConsole.WriteLine(s2.GetType().FullName); // System.String\n</code></pre>\n<p>It is recommended to use <code>string</code> over <code>String</code> but it's really a matter of choice. Most developers use <code>string</code> to declare variables in C# and use <code>System.String</code> class to use any built-in string methods like for an example , the <code>String.IsNullOrEmpty()</code> method.</p>\n"}, {'answer_id': 72477828, 'author': 'Nima Habibollahi', 'author_id': 1935499, 'author_profile': 'https://Stackoverflow.com/users/1935499', 'pm_score': -1, 'selected': False, 'text': "<p>There are at least 4 differences:</p>\n<p>1- string is a reserved word, but String is just a class name. This means that string cannot be used as a variable name by itself.</p>\n<p>2- you can't use String without &quot;using System&quot;.so you write less code by using &quot;string&quot;.</p>\n<p>3- 'String' is better naming convention than 'string', as it is a type not variable.</p>\n<p>4- &quot;string&quot; is a C# keyword and syntax highlighted in most coding editors, but not &quot;String&quot;.</p>\n"}, {'answer_id': 74266000, 'author': 'DanConsultant', 'author_id': 3991432, 'author_profile': 'https://Stackoverflow.com/users/3991432', 'pm_score': -1, 'selected': False, 'text': '<p>A good way to thing about it is string is a data type where String is a class type. Each have different methods and which one to use depends on your need.</p>\n'}]
['https://Stackoverflow.com/questions/7074', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/571/']