#generics

1 messages · Page 1 of 1 (latest)

rocky sierra
#

should we use generics in every everything

stoic onyx
#

No. You should use generics when it makes sense.
Oftentimes there is no need for use of Generics - or you can get away using a base class/interface instead.

rocky sierra
#

ok

autumn stratus
#
interface IFoo { }

struct Foo : IFoo { }

Now if you have:

void DoSomething(IFoo foo) { }

and you call it with DoSomething(instanceOfFoo), it'll box because interfaces are reference type. But if you have

void DoSomething<T>(T foo) where T : IFoo { }

this won't box, it'll maintain the type it is

smoky dock