What’s the difference between String and string

Most of the new developers will have this question and confusion if they need to use as string or String. To answer in simple, there is no difference between String and string. Both are same. a string is an alias in C# for System.String.

When declaring the variable of type string you can declare in both the ways as shown below and it doesn’t impact the performance in anyway. As told above string is an alias and String is a class. Many developers prefer to use as string as its a C# type alias. Finally, both are compiled to System.String in IL(Intermediate Language)

Code Snippet to find Difference between String and string

using System;
namespace StringExample
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = "Hello World";
            String b = "Hello C#";
            Console.WriteLine(a);
            Console.WriteLine(b);
            Console.ReadLine();
        }
    }
}

//Output of the above code would be
//Hello World
//Hello C#

Leave a Reply

Your email address will not be published. Required fields are marked *

Sign Up for Our Newsletters

Subscribe to get notified of the latest articles. We will never spam you. Be a part of our ever-growing community.

You May Also Like