Difference Between string and String in C#

Well technically both of these are the same but with a slight difference. While  “string” is a datatype, whereas “String” represents a class. “string” is an alias for System.String. At execution time both are compiled to the same code. One more difference is the syntax highlighter.

Let us now check a code snippet to understand both of these.

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. namespace ConsoleApplication2  
  7. {  
  8.     class Program  
  9.     {  
  10.         static void Main(string[] args)  
  11.         {  
  12.             string FirstName = ".Net";  
  13.             String Lastname = "Snippets";  
  14.             Console.WriteLine(FirstName + " " + Lastname);  
  15.             Console.ReadLine();  
  16.         }  
  17.     }  
  18. }  
If we hover above string and String we get reference to the same class. Refer to  the screenshots below.

String vs string



string Vs String



So both refer to the same class.