Change element in a string array : String Array « String « C# / CSharp Tutorial






using System; 
 
class MainClass {  
  public static void Main() {  
    string[] str = { "This", "is", "a", "test." };  
  
    Console.WriteLine("Original array: ");  
    for(int i=0; i < str.Length; i++) 
      Console.Write(str[i] + " ");  
    Console.WriteLine("\n");  
  
    // change a string  
    str[1] = "was";  
    str[3] = "test, too!";  
  
    Console.WriteLine("Modified array: "); 
    for(int i=0; i < str.Length; i++) 
      Console.Write(str[i] + " ");  
  }  
}
Original array:
This is a test.

Modified array:
This was a test, too!








5.5.String Array
5.5.1.Initialize string arrays
5.5.2.Change element in a string array
5.5.3.Use the Sort() method to sort the elements in a string array
5.5.4.A two-dimensional rectangular string array