Suppose I've a generic method as:
void Fun<T>(FunArg arg) {}
Are this.Fun<Feature>
and this.Fun<Category>
different instantiations of the generic method?
In general, how does the generic method get instantiated? Different generic argument produces different method, or same method along with different metadata which is used at runtime?
Please support your answer with some quote(s) from the language specification.
Also, suppose I did these:
client.SomeEvent += this.Fun<Feature>; //line1
client.SomeEvent += this.Fun<Category>; //line2
client.SomeEvent += this.Fun<Result>; //line3
then later on,
client.SomeEvent -= this.Fun<Feature>; //lineX
Does the lineX
undo the thing which I did at line1
? Or it depends on somethig else also?
var
declaration. Present valid code, and we can give a better answer. – ProcyonlineX
creates a new delegate instance usingFun<Feature>
(a specific, known-T, method); then delegate subtraction applies, which (because it is the sameMethodInfo
and same instance) cancels out the firstFun<Feature>
in the delegate list, leavingFun<Category>
andFun<Result>
– CousinsT
is a separateMethodInfo
, but there could still be some "sharing" (i.e. JIT sharing) - and they certainly share the same generic declaration. – CousinsFun<Feature>()
is different fromFun<Category>()
in the same way asFunFeature()
is different fromFunCategory()
. Can a C# programmer (not the compiler write) assume that? – Claudicant