Replies: 1 comment
-
Internally, types nested in a generic type have the outer type's generic parameters in addition to their own. Therefore, nesting an enum/class/struct in a covariant/contravariant interface would result in a covariant/contravariant enum/class/struct, which is not allowed. A possible workaround is to move the nested types to a superinterface: public interface I1Base
{
public enum MyEnum { }
public class MyClass { }
public struct MyStruct { }
}
public interface I1<out T1> : I1Base
{
public interface I2<T2> { }
} It will not be possible to use the covariant/contravariant type parameters in the nested enum/class/struct. Said another way, |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Just questions, why I can't declare a enum/class/struct in a covariant/contravariant interface?
And why I can declare an interface that not covariant/contravariant interface in a covariant/contravariant interface?
What is the difference between these two?
Beta Was this translation helpful? Give feedback.
All reactions