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

后端 未结 6 1164
囚心锁ツ
囚心锁ツ 2020-12-02 15:16

This is more of a documentation than a real question. This does not seem to have been addressed on SO yet (unless I missed it), so here goes:

Imagine a generic class

6条回答
  •  情歌与酒
    2020-12-02 15:29

    IMO, you need to test it, but I think that

    Foo.member = 1;
    Foo.member = 2;
    Console.WriteLine (Foo.member);
    

    will output 1 because I think that, during compilation, the compilator create 1 class for every generic class you use (in you example : Foo and Foo).

    But I'm not 100% sure =).

    Remark : I think it's not a good design nor a good practice to use such kind of static attributes.

提交回复
热议问题