c# - can i pass in IQueryable<Foo> into IQueryable<IFoo> if the object implements that interface? -


i have object a:

iqueryable<foo> 

and want pass function expects a:

iqueryable<ifoo> 

foo implements ifoo

why wouldn't compile? best way convert have work?

co- , contra- variance added in .net 4 bcl, , not exist in .net 3.5 bcl.

you can work around limitation in 3.5 using select operation cast interface type:

iqueryable<foo> foos = ..; myfunc(foos.select(x => (ifoo)x)); 

edit (from reed's comment, below):

iqueryable<foo> foos = ..; myfunc(foos.cast<ifoo>()); 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -