如何添加一个字符串到一个String []数组?有没有。新增功能 [英] How to add a string to a string[] array? There's no .Add function
本文介绍了如何添加一个字符串到一个String []数组?有没有。新增功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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
转换为字符串,然后把它添加到我的数组。我怎样才能做到这一点?
I'd like to convert the FI.Name
to a string and then add it to my array. How can I do this?
推荐答案
您不能将项目添加到一个数组,因为它有固定的长度,你要找的是一个列表<串&GT ;
,可以在以后使用变作一个数组 list.ToArray()
You can't add items to an array, since it has fixed length, what you're looking for is a List<string>
, which can later be turned to an array using list.ToArray()
.
这篇关于如何添加一个字符串到一个String []数组?有没有。新增功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文