C# 菜鸟问题:如何创建一维动态数组?以及以后如何更改?
谢谢。
最佳答案
您可以使用 List<>
而不是使用数组C# 中的对象。
List<int> integerList = new List<int>();
要迭代列表中包含的项目,请使用 foreach
运算符(operator):
foreach(int i in integerList)
{
// do stuff with i
}
您可以使用 Add()
在列表对象中添加项目和 Remove()
功能。
for(int i = 0; i < 10; i++)
{
integerList.Add(i);
}
integerList.Remove(6);
integerList.Remove(7);
您可以转换 List<T>
使用 ToArray()
到数组功能:
int[] integerArray = integerList.ToArray();
这是 documentation在 List<>
对象。
关于c# - 如何在 C# 中创建一维动态数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2676291/