Thi*_*ise 14
您可以List<>在C#中使用该对象,而不是使用数组.
List<int> integerList = new List<int>();
Run Code Online (Sandbox Code Playgroud)
要迭代列表中包含的项目,请使用foreach运算符:
foreach(int i in integerList)
{
// do stuff with i
}
Run Code Online (Sandbox Code Playgroud)
您可以使用Add()和Remove()功能在列表对象中添加项目.
for(int i = 0; i < 10; i++)
{
integerList.Add(i);
}
integerList.Remove(6);
integerList.Remove(7);
Run Code Online (Sandbox Code Playgroud)
您可以List<T>使用以下ToArray()函数将a转换为数组:
int[] integerArray = integerList.ToArray();
Run Code Online (Sandbox Code Playgroud)
这是关于对象的文档List<>.
| 归档时间: |
|
| 查看次数: |
8917 次 |
| 最近记录: |