What is the difference between String vs string? ( C# interview questions) ?

This is one of the most asked C# interview question to confused C# and .NET developers. I do understand that this question does not judge capability of a C# developer , but then when interviewers are asking it we need to have some answer ready for it.

You can also see the below video which is available in DotnetSpider video channel which explain String vs String.

"String" is an alias ( the same thing called with different names) of "string". So technically both the below code statements will give the same output.

String s = "C# interview questions";

string s = "C# interview questions";

In the same way there are aliases for other c# data type as shown below:-

object: System.Object
string: System.String
bool: System.Boolean
byte: System.Byte
sbyte: System.SByte
short: System.Int16
ushort: System.UInt16
int: System.Int32
uint: System.UInt32
long: System.Int64
ulong: System.UInt64
float: System.Single
double: System.Double
decimal: System.Decimal
char: System.Char

So when both mean the same thing why are they different?

When we talk about .NET there are two different things one there is .NET framework and the other there are languages ( C# , VB.NET etc) which use that framework.


"System.String" a.k.a "String" ( capital "S") is a .NET framework data type while "string" is a C# data type.

c# interview questions

So when to use "String" and "string"?

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 "string" ( small "s") and when you are using it as a class name then "String" ( capital "S") is preferred.

In the below code the left hand side is a variable declaration and it declared using "string". At the right hand side we are calling a method so "String" is more sensible.

string s = String.ToUpper() ;


Guest Author: Monish Kumar Tarai09 Jan 2014

Thank you very much

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: