C# String Chars

Description

String Chars gets the Char object at a specified position in the current String object.

Syntax

String.Chars has the following syntax.


public char this[
  int index
] { get; }

Parameters

String.Chars has the following parameters.

  • index - A position in the current string.

Example

In C#, the Chars property is an indexer.


//from   ww  w. j a va  2s  . com
using System;
public class MainClass{
  public static void Main(String[] argv){  
    string str1 = "Test";
    for (int ctr = 0; ctr <= str1.Length - 1; ctr++ ){
       Console.Write("{0} ", str1[ctr]);
    }
  }
}

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