If I write a method accepting a parameter which derives from a BaseClass
(or an interface), as far as I know there are two ways to achieve that:
voi
When T
is constrained to a base class, there is not really much difference apart from what has already been stated.
When T
is constrained to an interface, the difference can be huge:
int FrobNonGeneric(IFrobbable frob) { //... }
int Frob(T frob) where T: IFrobbable { //... }
struct Frob: IFrobbable { ... }
FrobNonGeneric(new Frob()); //boxing!
Frob(new Frob()); //no boxing