In the .NET Framework, at least in the C# language, we have two "versions" of the string type:

  • "string"
  • "String"

It appears that they are interchangeable, but are they really? If they are not interchangeable, is it generally better to use one instead of the other, and under what circumstances?

  • 1
    Similar to this question: stackoverflow.com/q/6000517/6504
    – Agent_9191
    Commented Apr 11, 2012 at 21:24
  • 2
    Stylistically, I tend to use the lower-case version when I'm referring to the type, and the upper-case version when I'm calling a static method of System.String. Commented Apr 11, 2012 at 22:38
  • 4
    Identical to stackoverflow.com/questions/7074/….
    – zzzzBov
    Commented Apr 12, 2012 at 4:30
  • 2
    string does not exist in .net, it only exists in C#. Commented Apr 12, 2012 at 17:41
  • 1
    Although this might be a bit more suitable for Stack Overflow, I don't think it's completely off topic for Programmers, and since Stack Overflow already has at least one duplicate there wouldn't be much point in migrating this. So please stop flagging / close voting to migrate, if you feel this should be closed, that's cool, but it should be closed not migrated.
    – yannis
    Commented Apr 13, 2012 at 8:58

6 Answers 6


Well according to the MSDN

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

Where "String" is in fact System.String.

I would say that they are interchangeable and there is no difference when and where you should use one or the other.

It would be better to be consistent with which one you did use though.

  • for some reason I had it in my head that String was a class wrapper around a value typed string and this leads to the idea of boxing... am i totally wrong here? Commented Apr 11, 2012 at 22:30
  • 1
    @Gabriel No, String (and hence string by alias) are reference types. Commented Apr 11, 2012 at 22:57
  • @Gabriel: doesn't Java do that with stuff like byte vs Byte? Commented Apr 12, 2012 at 4:23
  • Is the same also true for Double vs double, and other data types? Commented Apr 12, 2012 at 9:18
  • 1
    @AaronAnodide I believe that's a Java convention, which is probably where you heard of it.
    – KChaloux
    Commented May 1, 2014 at 12:28

As pointed out, they are the same thing and string is just an alias to String.

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 - int, bool, var etc (although Int32 and Boolean are also correct).

I use String when using the static methods on the String class, like String.Split() or String.IsNullOrEmpty(). 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.

  • We use this convention at work as well, and I like it. My brain automatically makes the connection.
    – SBI
    Commented May 1, 2014 at 11:18
  • I have always done the same or the same reason. Glad I'm not the only one. Annoyed how Visual Studio now suggests (nags) changing String to string is "simplifying".
    – xr280xr
    Commented Apr 9, 2020 at 22:06

I'd suggest using lowercase string. Uppercase String will use the first class named String it finds in the imported namespaces ... which is generally System.String. It's possible for your own String class to be used instead.

  • 3
    If you have two different imported types with the same name, and you use that name without namespace qualification, you will get an error.
    – svick
    Commented Apr 11, 2012 at 22:02
  • It's possible to trick String into working, it's never possible to trick string. Commented Apr 11, 2012 at 22:04
  • Still, I don't think that's a good enough reason to use string.
    – svick
    Commented Apr 11, 2012 at 22:05
  • 5
    How is "one might break" vs. "one will never break" with all else being identical not a good enough reason? Commented Apr 11, 2012 at 22:24

string is a C# keyword which is simply an alias for the System.String

..but as it's a keyword, your syntax colouring editor/IDE will show it in keyword colour, same as int, double, if, else, etc. Stylistically, you may prefer to use the keyword rather than the System.String type (or just String after you've done using System;).

This is a niche point though, as although bool, char, int, double and string are all keyword aliases for system types, string is an odd-one-out as it is a reference type and the others are value types.

  • 4
    object is a keyword alias for a reference type, too
    – nikie
    Commented Apr 12, 2012 at 9:24
  • Oh yes, I forgot all about that one - thanks for reminder. Commented Apr 12, 2012 at 12:22

string is just an alias for String, they're ultimately the same.

You can use whichever you prefer, although I generally use string when I'm planning on using it much like a primitive data type (similar to int, float, or bool) and String when I'm planning on using it as an object/class. For example:

string foo = "   ";
if (String.isNullOrWhitespace(foo)) 
    // ...

In the case above, I'm planning on using foo simply to store some text (effectively as a primitive), so I use string; however, when I call String.isNullOrWhitespace(string) I use String. I do this, because generally the first letter of class names are capitalized (String) while the first letter of primitives (such as int) are not.


String is used with namespace System.String, string is used C# compiler specification, moreover System.String is reference type value. You are preferred to deal with System objects, string for literals purposes only. System and system both working is same.

string TC = new System.String('/', 5);

String is used for comparing, equal and other purposes as well.

  • 4
    this doesn't seem to offer anything substantial over prior 6 answers
    – gnat
    Commented May 1, 2014 at 11:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.