小编Win*_*cky的帖子

C# 使用 array.Where in Arraylist

我在 C# 中有一组带有数组的代码,我需要将数组拆分为更小的数组。声明数组时我没有错误:

List<int> array = new List<int>();
Run Code Online (Sandbox Code Playgroud)

但是,代码执行在数组中提示错误。当我声明为时

var array = new ArrayList();
Run Code Online (Sandbox Code Playgroud)

有什么办法可以使用数组。数组列表中的位置?下面是我的代码:

List<int> array = new List<int>();

for (int i = 0; i <=20; i++){
  if (unitIsPresent) 
  {
    array.add(1);
  } 
  else
  {
    array.add(0)
  }
}

devidedArray = array.Where((e, i) => i >= 5 && i < 10).ToArray();
Run Code Online (Sandbox Code Playgroud)

c# arrays

2
推荐指数
2
解决办法
104
查看次数

标签 统计

arrays ×1

c# ×1