我正在用 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/