I don’t see what I’m doing wrong with the LINQ query below.
I’m building a generic type:
public class MyClass<TKey, TValue> : IList<TValue> { ... }
Within this class I declare a nested private type:
private class Pair {
public TKey Key { get; set; }
public TValue Value { get; set; }
public Pair() {
Key = default( TKey );
Value = default( TValue );
}
}
So far so good. Now, in MyClass I have a method which has an array of TKey objects. I want to use LINQ to extract a page of TKey objects and create a smaller array of Pair objects. Here’s the query I’ve built:
TKey[] Keys = ...;
IQueryable<Pair> query = from key in Keys
select new Pair { Key = key, Value = default( TValue ) };
When I compile the program, I get the following error on the line with the select in it:
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?)
What am I doing wrong?
Tony
Try this: