The Tech Platform
May 9, 20221 min
String (capital S) is a class in the .NET framework in the System namespace. The fully qualified name is System.String. Whereas, the lower case string is an alias of System.String.
It is recommended to use string (lower case) over String. However, it's a matter of choice. You can use any of them. Many developers use string to declare variables in C# and use System.String class to use any built-in string methods e.g., String.IsNullOrEmpty().
Example:
using System;
public class Program
{
public static void Main()
{
string str1 = "Hello";
String str2 = "World!";
Console.WriteLine(str1.GetType().FullName);
Console.WriteLine(str2.GetType().FullName);
}
}
Alias .NET Type
byte System.Byte
sbyte System.SByte
int System.Int32
uint System.UInt32
short System.Int16
ushort System.UInt16
long System.Int64
ulong System.UInt64
float System.Single
double System.Double
char System.Char
bool System.Boolean
object System.Object
string System.String
decimal System.Decimal
DateTime System.DateTime
The Tech Platform