String vs string ( C# interview questions with answers)


“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 which explains the same in depth.


About c# and .NET Interview questions

This blog is for developers who want to crack .NET and C# interviews. It has all tips and tricks needed to crack .NET interviews , C# interview , SQL Server interview , Java interview , WCF Interview , Silverlight interview , WPF interview , LINQ interview , Entity framework Interview. Do not forget to watch our Learn step by step video series. Learn MVC in 16 hours:- Learn AngularJS Step by Step:- Learn Design Pattern in 8 hours:- Learn C# and .NET in 60 days:- Learn MSBI in 32 hours:- Learn SharePoint Step by Step in 8 hours:-
This entry was posted in Uncategorized and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s