我有以下字典宣稱「不能從使用推斷」:LAMBDA
private readonly Dictionary<int, Image> dictionary;
而且我有一個方法,這是造成一個編譯器錯誤:
public IQueryable<Image> Find(Func<Image, bool> exp)
{
return dictionary.Single(exp);
}
的錯誤,我得到是:
Error 1 The type arguments for method 'System.Linq.Enumerable.Single<TSource>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,bool>)' cannot be inferred from the usage. Try specifying the type arguments explicitly. C:\work\MSD-AIDS-Images\MSD-AIDS-Images-Test\TestImageRepository.cs 34 30 MSD-AIDS-Images-Test
我已經試着用搜索引擎的時候,我似乎無法找到任何明確的,以什麼我做錯了
編輯 - 這是星期一上午在工作。
我的意思是把 「地方」,而不是單一
編輯2!
好了,現在的代碼是這樣的:
public IQueryable<Image> Find(Func<Image, bool> exp)
{
return dictionary.Values.Where(exp);
}
現在我得到以下錯誤:
Error 1 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<MSD_AIDS_Images_Data.Image>' to 'System.Linq.IQueryable<MSD_AIDS_Images_Data.Image>'. An explicit conversion exists (are you missing a cast?) C:\work\MSD-AIDS-Images\MSD-AIDS-Images-Test\TestImageRepository.cs 34 20 MSD-AIDS-Images-Test
作爲一個供參考,對於實現一個接口,聲明的方法那就是:
IQueryable<T> Find(Func<T, bool> exp);
這已經變得比它應該更復雜了!
正如我已經說過 - 返回類型更改爲IEnumerable的 –
2009-02-09 15:18:58