For type safety, C # 4.0 supports covariance / contravariance ONLY for type parameters marked in or out .
, , . , CLR . , :
public class Stack<T>
{
int position;
T[] data = new T[100];
public void Push (T obj) { data[position++] = obj; }
public T Pop() { return data[--position]; }
}
, , . , - # / .
. : Stack :
public interface IPoppable<out T> { T Pop(); }
public interface IPushable<in T> { void Push (T obj); }
, T IPoppable IPushable. , T , - , IPoppable IPushable.
, / , , , . , , . Enumerable - ?