C#中的数组是不支持动态添加元素的,只能创建固定大小的数组。
解决方法:可以使用List
List<string> result = new List<string>();
for (int i = 0; i < 5; i++ )
{
result.Add(i.ToString());
}之后也可以转为数组类型:
string[] strArray = result.ToArray();附:遍历List中的元素
foreach (T element in mList)
{
Console.WriteLine(element);
}
版权声明:本文为BockSong原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。