This is the first time I asked a question, so help me in advance (and possibly others) in advance.
Today I was puzzled by covariance and contravariance in C # 4, but I really do not see the opportunity to do what I wanted. NOTE: all that should NOT solve a specific problem, but I would like to know if there is any legal way (brand-new co / contra-variance in C # 4) to solve this problem. So don't go crazy ...
Here is a sample code:
public interface IBase<in T>
{
T GetValue();
...
}
public class Readable<T> : IBase<T>
{
public T GetValue() {}
...
}
public class Writeable<T> : IBase<T>
{
public T GetValue() {}
public void SetValue(T value) {}
...
}
public class Program
{
private List<IBase<object>> _collection = new List<IBase<object>>();
public static void Main()
{
var p = new Program();
p._collection.Add(new Readable<bool>());
}
}
IBase, T.
, - , .
- IBaseCore, IBase .
: , IBase IBase?
.