What options do I have when initializing string[]
object?
This question is related to
c#
arrays
initialization
string[] str = new string[]{"1","2"};
string[] str = new string[4];
Basic:
string[] myString = new string[]{"string1", "string2"};
or
string[] myString = new string[4];
myString[0] = "string1"; // etc.
Advanced: From a List
list<string> = new list<string>();
//... read this in from somewhere
string[] myString = list.ToArray();
From StringCollection
StringCollection sc = new StringCollection();
/// read in from file or something
string[] myString = sc.ToArray();
Source: Stackoverflow.com