【问题标题】:C# error CS1061: Type `System.Collections.Generic.List<int>' does not contain a definition for `Length'C# 错误 CS1061:类型“System.Collections.Generic.List<int>”不包含“长度”的定义
【发布时间】:2015-11-09 15:58:55
【问题描述】:

我正在使用 C# 进行编程,但我不断收到错误消息:“错误 CS1061:类型 System.Collections.Generic.List&lt;int&gt;' does not contain a definition forLength”并且找不到扩展方法 Length' of typeSystem.Collections.Generic.List'。您是否缺少程序集参考?:

我也添加了使用 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

标签: c# linq generics dictionary


【解决方案1】:

List&lt;T&gt; 上没有 Length 属性。改用Count 并用于实现ICollection 的其他类。

Length 通常只用于数组。

【讨论】:

  • 啊,这太容易了!非常感谢!
猜你喜欢
  • 1970-01-01
  • 2020-12-31
  • 2011-08-21
  • 2023-03-20
  • 2018-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多