C#错误CS1061:类型`System.Collections.Generic.List<int>'不包含名为`Length'的定义。

3
我正在使用C#编程并不断收到错误提示:"error CS1061: Type System.Collections.Generic.List<int>' does not contain a definition forLength' and no extension method Length' of typeSystem.Collections.Generic.List' could be found. Are you missing an assembly reference?"。
我已经添加了using System.Linq语句,这是解决许多类似问题的方法,但它仍然无法解决问题。
 Dictionary<string, int> decryptedPossibilites = new Dictionary<string, int>();
 foreach(KeyValuePair<string, int> entry in decryptedPossibilites){
      int eCount = entry.Key.Split('E').Length - 1;
      eCountList.Add(eCount);
  }

  int temp = 0;

  for (int write = 0; write < eCountList.Length; write++){
      for (int sort = 0; sort < eCountList.Length - 1; sort++){
          if (eCountList[sort] > eCountList[sort + 1]){
              temp = eCountList[sort + 1];
              eCountList[sort + 1] = eCountList[sort];
              eCountList[sort] = temp;
            }
        }
    }

  foreach(int q in eCountList){
        Console.WriteLine(q);
  }

我该怎么修复这个问题?

Length --> 数组;Count --> ListSet等。 - Sergey Kalinichenko
1个回答

19

List<T> 没有 Length 属性。而对于实现了 ICollection 接口的其它类,请使用Count

Length 通常仅用于数组。


啊,这太容易了!非常感谢! - Andrew1996

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接