C# 错误 CS1061 : Type `System.Collections.Generic.List<int>' does not contain a definition for `Length'

标签 c# linq generics dictionary

我正在用 C# 编程,但不断收到错误消息:“错误 CS1061:类型 System.Collections.Generic.List<int>' does not contain a definition for 长度”,但找不到扩展方法 Length' of type System.Collections.Generic.List。您是否缺少程序集引用?:

我还添加了 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属性(property) List<T> .使用 Count 相反,对于其他实现 ICollection 的类.

Length通常仅适用于数组。

关于C# 错误 CS1061 : Type `System.Collections.Generic.List<int>' does not contain a definition for `Length' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33613102/

相关文章:

c# - "Class does not implement interface member"类实现通用接口(interface)时出错

java - 如何使用 Jackson Databind 反序列化嵌套泛型类?

delphi - 如何获取泛型类方法的方法地址?

c# - 如何在具有原始参数的浏览器中测试Web服务方法?

c# - 使用 LINQ 使用 2 个列表创建字典

c# - 如果有可能找不到该元素,我应该使用 Single() 还是 SingleOrDefault()?

c# - DocumentDB LinQ 请求率大

c# - 为什么绑定(bind)不适用于动画?

c# - 公开包含方法

c# - ServiceStack.OrmLite - 我可以做类似 Db.Select<Foo, Bar>() 的事情吗?