Create a string array in CSharp

Description

The following code shows how to create a string array.

Example


  //  w w w . ja  v a2 s  .co  m
 
using System; 
 
public class StringArrays {  
  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] + " ");  
  }  
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var