当我在VB.NET中尝试以下操作时:
我在.Net Fiddle上遇到了这个编译错误:
似乎找不到正确的重载方法。
奇怪的是,这个 C# 版本在 Visual Studio 中运行良好(但在 .NET Fiddle 中失败了 - 奇怪...发生了什么?):
Dim data = New Dictionary(Of String, Integer)
data.Count(Function(x) x.Value > 0) 'Compile-time error!
我在.Net Fiddle上遇到了这个编译错误:
Visual Studio 给出了以下错误提示:参数过多:'Public Overloads ReadOnly Property Count As Integer'
不过下面的代码可以正常工作:'Public ReadOnly Property Count As Integer' 没有参数,其返回类型不能被索引。
Enumerable.Where(data, Function(x) x.Value > 0).Count() 'Works!
data.Where(Function(x) x.Value > 0).Count() 'Works!
似乎找不到正确的重载方法。
奇怪的是,这个 C# 版本在 Visual Studio 中运行良好(但在 .NET Fiddle 中失败了 - 奇怪...发生了什么?):
var data = new Dictionary<string, int>();
data.Count(x => x.Value > 0);
如何正确使用带有谓词的LINQ版本的.Count()
来针对字典进行操作?