In this case, there is no difference. Generics are used for stream type information. As soon as you want to call another code or return a value, and that value should be statically printed in the same way as the input parameter bc , you need generics.
For example, the two functions below output the same thing, but the second saves information like:
object PrintAndReturn1(object obj) { Console.WriteLine(obj); return obj; } T PrintAndReturn2<T>(T obj) { Console.WriteLine(obj); return obj; }
Generics come into play when you want to save type information. If you only ever consume a value and don't skip it, inheritance is enough.
You say you did not find a difference during testing. This makes sense, as JIT erases information about the generic type (mostly). JITed code will be very similar to both options. Virtual calls to links to a common type are implemented in the same way as non-shared v-calls. (Note that this applies only to reference types. All link types have the same JITed code type.)
usr
source share