C# Initialize a String Array

To initialize a String Array in C#, declare a variable of type string[] and assign the comma separated values enclosed in flower braces to the array variable.

Example

In the following example, we initialize a string array in a variable arr, and print the contents of this array to console.

Program.cs

</>
Copy
using System;

namespace CSharpExamples {
    class Program {
        static void Main(string[] args) {
            string[] arr = {"apple", "banana", "cherry"};

            Console.WriteLine("String Array :");
            for (int i=0; i < arr.Length; i++) {
                Console.WriteLine(arr[i]);
            }
        }
    }
}

Output

String Array :
apple
banana
cherry

Conclusion

In this C# Tutorial, we learned how to initialize a string array, with examples.