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


This is more than a real question. It does not seem that so far (unless I miss it), then it goes here:

Imagine a common square with a stable member:

  square fu & lt; T & gt; {Public Static Ent member; }  

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

This can be easily verified by code like this:

  Foo < Int & gt; .member = 1; Foo & lt; String & gt; .member = 2; Console.lightline (foo  member);  

What is the result, and where is this behavior?

A static area is shared in all instances one The same type . foo & lt; Int & gt; and foo & lt; String & gt; There are two different types that can be proven by the code of the following code:

  // This prints "wrong" console. WrightLine (type (fu ) == type (Foo  gt;));  

Where it is documented, the following C language specificity (for C # 3) has been found in the 1.6.5 field :

A static field identifies exactly one storage space, how many instances of any class are being created, no static is only a copy of any static field.

As told before; foo & lt; Int & gt; and foo & lt; String & gt; is not the same category; They are two separate classes created from the same general class. This is how it is mentioned in Section 4.4 of the above mentioned document:

A general type of declaration, by itself, shows an unbound general type by itself, which is different in the form of "blue print" - is used as a different type, by applying type arguments.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -