Hi

C#, you can assign values to a string[] (string array)

 1. Inline Assignment with Values


string[] tFile = { "file1.txt", "file2.txt", "file3.txt" };


2. Using new Keyword with Initializer


string[] tFile = new string[] { "file1.txt", "file2.txt", "file3.txt" };

3. Declaring Array Size First, Then Assigning


string[] tFile = new string[3]; tFile[0] = "file1.txt"; tFile[1] = "file2.txt"; tFile[2] = "file3.txt";

 4. From a List


List<string> fileList = new List<string> { "file1.txt", "file2.txt" }; string[] tFile = fileList.ToArray();

 Example Usage in a Loop:


foreach (string file in tFile) { Console.WriteLine(file); }
Previous
Next Post »