c# - Put a struct as a generic covariant parameter -


I have been a covariant interface, which is the parental type in an array of it. They are globally defined like this:

  // interface / class public interface IMyType & LT; Outside T & gt; {} Public Sector MyType & LT; T & gt;: IMyType & lt; T & gt; {T value; MyType & lt; T & gt; (T initial value) {value = initialValue; }}  

I tried to do this:

  IMyType & lt; Object & gt; [] TT = new IMyType & LT; Object & gt; [] {New MyType & LT; String & gt; ("Test"), // works fine new MyType & LT; SomeOtherRandomClass & gt; (New SomeOtherRandomClass ()), // works fine new MyType & LT; Int32 & gt; (12) // does not work};  

Even trying to specify an entity instead of the object:

  IMyType & LT; Struct & gt; [] TT = new IMyType & LT; Struct & gt; [] // does not work: the number of incorrect parameters {new MyType & LT; Int32 & gt; (12) // does not work};  

Only a specific structure works: specify

  IMyType & lt; Integer & gt; [] TT = new IMyType & LT; Integer & gt; [] // does work {new MyType & LT; Int32 & gt; (12) // does work};  

So why does not it work? Is this a way to work?

This is a interface < Value type & gt; Interface & lt; Object & gt; as a sect conversion.

The reason for this is that JITTER should compile a different version of your class for each value type (since the price types are different), so it did not convert it to any other normal acceleration Can go.

Variance only works for reference types because the references are all the same, so the methods used can be shared differently.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -