Use Indexer to reference chars in a string : String : String C# Examples


C# Examples » String » String »

 

Use Indexer to reference chars in a string









    
using  System;

class  MainClass
{

    public  static  void  Main()
    {
        string  myString  =  "To  be  or  not  to  be";

        
        for  (int  count  =  0;  count  <  myString.Length;  count++)
        {
            Console.WriteLine("myString["  +  count  +  "]  =  "  +  myString[count]);
        }

    }

}
    
   
  
   



Output

myString[0] = T
myString[1] = o
myString[2] =
myString[3] = b
myString[4] = e
myString[5] =
myString[6] = o
myString[7] = r
myString[8] =
myString[9] = n
myString[10] = o
myString[11] = t
myString[12] =
myString[13] = t
myString[14] = o
myString[15] =
myString[16] = b
myString[17] = e


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo String
» String