C# String Length

Description

String Length gets the number of characters in the current String object.

Syntax

String.Length has the following syntax.


public int Length { get; }

Example

The following example demonstrates the Length property.


using System;//  w  w  w  . j a  v a2 s .  co m

class Sample 
{
    public static void Main() 
    {
    string str = "java2s.com";
    Console.WriteLine("1) The length of '{0}' is {1}", str, str.Length);
    Console.WriteLine("2) The length of '{0}' is {1}", "xyz", "xyz".Length);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version