文字列をstring[]配列に追加するにはどうすればよいですか? .Add関数はありません 質問する

文字列をstring[]配列に追加するにはどうすればよいですか? .Add関数はありません 質問する
private string[] ColeccionDeCortes(string Path)
{
    DirectoryInfo X = new DirectoryInfo(Path);
    FileInfo[] listaDeArchivos = X.GetFiles();
    string[] Coleccion;

    foreach (FileInfo FI in listaDeArchivos)
    {
        //Add the FI.Name to the Coleccion[] array, 
    }

    return Coleccion;
}

FI.Nameを文字列に変換して配列に追加したいと思います。どうすればいいでしょうか?

ベストアンサー1

配列は長さが固定されているため、要素を追加することはできません。探しているのは でありList<string>、これは後で を使用して配列に変換できますlist.ToArray()。例:

List<string> list = new List<string>();
list.Add("Hi");
String[] str = list.ToArray();

おすすめ記事