I've read some information about generics in .ΝΕΤ and noticed one interesting thing.
For example, if I have a generic class:
class Foo<T>
{
public static int Counter;
}
Console.WriteLine(++Foo<int>.Counter); //1
Console.WriteLine(++Foo<string>.Counter); //1
Two classes Foo<int>
and Foo<string>
are different at runtime. But what about case when non-generic class having generic method?
class Foo
{
public void Bar<T>()
{
}
}
It's obvious that there's only one Foo
class. But what about method Bar
? All the generic classes and methods are closed at runtime with parameters they used with. Does it mean that class Foo
has many implementations of Bar
and where the information about this method stored in memory?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…