我不明白我在做什麼錯誤的LINQ查詢如下。涉及仿製藥不能正常工作的LINQ查詢
我建立一個泛型類型:
public class MyClass<TKey, TValue> : IList<TValue> { ... }
在這個班,我宣佈一個嵌套的私有類型:
private class Pair {
public TKey Key { get; set; }
public TValue Value { get; set; }
public Pair() {
Key = default(TKey);
Value = default(TValue);
}
}
到目前爲止好。現在,在MyClass
我有一個方法,它有一個TKey
對象的數組。我想使用LINQ來抽取一個TKey
對象的頁面並創建一個更小的對象列表Pair
。這裏的查詢我已經建立:
TKey[] Keys = ...;
IQueryable<Pair> query = from key in Keys
select new Pair { Key = key, Value = default(TValue) };
當我編譯程序時,我得到就行了以下錯誤,在它的選擇:
Cannot implicitly convert type
'System.Collections.Generic.IEnumerable<MyNameSpace.MyClass<TKey,TValue>.Pair>'
to 'System.Linq.IQueryable<VirtualLoadApp.MyClass<TKey,TValue>.Pair>'.
An explicit conversion exists (are you missing a cast?)
我在做什麼錯?
託尼
是什麼錯誤消息說? –
錯誤消息的文本在問題的末尾。 –