Home Asp.net What is the difference between String and string in Asp.net C#?

What is the difference between String and string in Asp.net C#?

Redirect Page on Button Click

In my previous tutorials, I’d explained the difference between String and StringBuilder, difference between executereader executenonquery and executescalar, difference between dataset datareader dataadapter and dataview and other similar tutorials on Difference, Asp.net here.

In the .NET Framework, at least in the C# language, we have available two types of string class, they are String and string. So, many developers are confused about both types of classes and want to know the difference between them. So, here in this tutorial I’ll explain the difference between String and string in asp.net c# and also explain which one is best and appropriate to use among them.

Here is the example of two different class types:

Example of “string” – [C#]

string strSmall = "AspnetO - Quick Way To Learn Asp.net";

Example of “String” – [C#]

String strBig = "AspnetO - Quick Way To Learn Asp.net";

As you can see the only difference between both the examples is string and String. Right?
Yes exactly! So technically, there is no difference between both of them. In general, string is an alias for System.String. It’s same like int and System.Int32.

So, now the question raise in our mind is which one is the best and appropriate to use?

Which one is best string or String?

Generally, that’s not the case because using string is equals to System.String. They compile to the same code, so at the execution time there is no difference whatsoever. So, I would say that they are interchangeable and there is no difference when and where you should use one or the other.

But as far as I aware, I recommend you to use string when you’re referring to an object. For example:

string strTest = "AspnetO - Quick Way To Learn Asp.net";

And recommend using String when you need to refer specifically to the class. For example:

string strTestClass = String.Format("{0} - Quick Way To Learn Asp.net", "AspnetO");

Few Examples of Aliases in C#

The string and String is one of the aliases in C#. There are several others, here they are:

  • using byte is equal to System.Byte
  • using bool is equal to System.Boolean
  • using short is equal to System.Int16
  • using int is equal to System.Int32
  • using long is equal to System.Int64
  • using double is equal to System.Double
  • using decimal is equal to System.Decimal
  • using char is equal to System.Char
Previous articleSend HTML Webpage Content as Email Body in Asp.net C# Vb.net
Next articleHow to Print GridView Data in Asp .Net on Button Click using Javascript?
Hi there, I am Mayank, the man behind Technical Mack. I started AspnetO with a motive to educate people on various programming languages ranging from beginners to expert level. Through this blog, I aim to provide more insightful content.


Please enter your comment!
Please enter your name here

eighteen − 17 =