當我嘗試使用.Count之間的()在VB.NET以下無法從LINQ的字典
Dim data = New Dictionary(Of String, Integer)
data.Count(Function(x) x.Value > 0) 'Compile-time error!
我得到這個編譯錯誤與.Net Fiddle:
Too many arguments to 'Public Overloads ReadOnly Property Count As Integer'
的Visual Studio給我這個錯誤:
'Public ReadOnly Property Count As Integer' has no parameters and its return type cannot be indexed.
下面做工作,但:
Enumerable.Where(data, Function(x) x.Value > 0).Count() 'Works!
data.Where(Function(x) x.Value > 0).Count() 'Works!
它似乎沒有找到正確的過載。
奇怪的是,夠本了C#版本Visual Studio中工作得很好(但在.NET小提琴失敗 - 奇......這是怎麼回事?):
var data = new Dictionary<string, int>();
data.Count(x => x.Value > 0);
什麼是正確的方法對字典使用LINQ版本.Count()
with a predicate?
相關:http://stackoverflow.com/q/18743457/945456 –