C #, problem with generic types

I have a base class:

class ARBase<T> : ActiveRecordValidationBase<T> where T : class
{
}

and several child classes

class Producent : ARBase<Producent>
{
}

class Supplier : ARBase<Supplier>
{
}

Now in another class I want to have a property like:

public IList<ARBase<Object>> MyCollection 
{
}

and you want to be able to assign a collection of suppliers or a collection of Producent, but I get an error: cannot cast List<Producent>to IList<ARBase<Object>>...

Does anyone know a solution?

+3
source share
1 answer

, .NET- ​​ - , , # 4. (IList<T> .NET 4.0, T "in", "out".)

, , , - Supplier Producer - , , , a List<Producer> IList<ARBase<object>>.

, ? , .

+3

Source: https://habr.com/ru/post/1729710/


All Articles