c# - T must be contravariantly valid -
what wrong this?
interface irepository<out t> t : ibusinessentity { iqueryable<t> getall(); void save(t t); void delete(t t); }
it says:
invalid variance: type parameter 't' must contravariantly valid on 'mynamespace.irepository.delete(t)'. 't' covariant.
consider happen if compiler allowed that:
interface ir<out t> { void d(t t); } class c : ir<mammal> { public void d(mammal m) { m.growhair(); } } ... ir<animal> x = new c(); // legal because t covariant , mammal convertible animal x.d(new fish()); // legal because ir<animal>.d takes animal
and tried grow hair on fish.
the "out" means "t used in output positions". using in input position.
Comments
Post a Comment