I posted a c# feature request here; however, I do not get a lot of attention there. Therefore I am asking you here, what you think of it.
The in and out keywords in generic type declarations are useful; however, due to their nature, their application is limited to a small number of types. What I am suggesting here, is to be able to use them in declarations of variables, fields, parameters and possibly properties in order to restrict the set of possible operations on any generic type in a dynamic and temporary way. This would considerably increase the cases where co- and contravariance could be used.
Examples
// A List of a more derived type can be passed
public void ReadList(IList<out MyType> list)
{
MyType item = list[0]; // OK
list[0] = new MyType(); // DISALLOWED because of "out" keyword!
list.Add(new MyType()); // DISALLOWED because of "out" keyword!
}
// A List of a less derived type can be passed
public void WriteList(List<in MyType> list)
{
MyType item = list[0]; // DISALLOWED because of "in" keyword!
list[0] = new MyType(); // OK
list.Add(new MyType()); // OK
}
--
UPDATE
Taken these declarations
class LessDerived { }
class MyType : LessDerived { }
class MoreDerived : MyType { }
You could use the methods shown above like this
var listOfLessDerived = new List<LessDerived>();
var listOfMyType = new List<MyType >();
var listOfMoreDerived = new List<MoreDerived>();
ReadList(listOfMyType);
ReadList(listOfMoreDerived);
WriteList(listOfMyType);
WriteList(listOfLessDerived);

IList<T>orList<T>) where the generic parameter is used as input as well as output type cannot be used in co- or contravariance. If it was either restricted to be used only as input or as output in certain situations, then contra- respectively covariance would apply. By operation I mean either reading (getting) or writing (setting). – Olivier Jacot-Descombes Apr 27 '12 at 16:29public static void Add<T, U>(List<T> list, U obj) where U : T { list.Add(obj); }– Telastyn Apr 27 '12 at 18:40