Are static members of a generic class tied to the specific instance?

Posted by mafutrct on Stack Overflow See other posts from Stack Overflow or by mafutrct
Published on 2010-06-14T12:34:38Z Indexed on 2010/06/14 12:42 UTC
Read the original article Hit count: 108

Filed under:
|
|
|

This is more of a documentation than a real question. I noticed the principle it is not described on SO yet (did I miss it?), so here goes:

Imagine a generic class that contains a static member:

class Foo<T> {
    public static int member;
}

Is there a new instance of the member for each specific class, or is there only a single instance for all Foo-type classes?

It can easily be verified by code like this:

Foo<int>.member = 1;
Foo<string>.member = 2;
Console.WriteLine (Foo<int>.member);

What is the result, and where is this behavior documented?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET