Use the String.Length property in C# to get the length of the string.
str.Length
The property calculates the words in the string and displays the length of the specified string, for example, the string Amit has 4 characters −
string str = "Amit";
Example
The following is the C# program to calculate the string length −
using System;
using System.Collections;
namespace Demo {
class Program {
static void Main(string[] args) {
string str = "Amit";
Console.WriteLine("String: "+str);
Console.WriteLine("String Length: "+str.Length);
Console.ReadKey();
}
}
}Output
String: Amit String Length: 4