“String” is an alias 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:-
- Int16 → short
- Int32 → int
- Int64 → long
So when both mean the same thing why are they different?
Note :- Interviewers are typical creatures we cannot argue with them. In case the interviewer stresses why there are different names, below is a logical reasoning for it.
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() ;
In the same line one of the favorite C# question is explain the difference between string and stringbuilder , below is a nice video created by www.questpond.com which explains the same in depth.