文字列のコレクションを表せます。
StringCollection sc = new StringCollection(); sc.Add("a"); sc.Add("b"); sc.Insert(1, "z"); sc.Remove("a"); int index = sc.IndexOf("z"); bool contain = sc.Contains("b"); foreach (string item in sc) { Console.Write(item); }
StringCollection全体を、Arrayへコピーできます。
void ICollection.CopyTo (Array array, int index);StringCollection.ICollection.CopyTo(Array, Int32) メソッド (System.Collections.Specialized) | Microsoft Learn
StringCollection sc = new StringCollection(); sc.AddRange(new[] { "a", "b" }); string[] arr = new string[sc.Count]; sc.CopyTo(arr, 0);
これをIEnumerable<string>とするには、Cast<string>()でキャストします。