<out T> vs <T> in Generics
问题 What is the difference between <out T> and <T> ? For example: public interface IExample<out T> { ... } vs. public interface IExample<T> { ... } 回答1: The out keyword in generics is used to denote that the type T in the interface is covariant. See Covariance and contravariance for details. The classic example is IEnumerable<out T> . Since IEnumerable<out T> is covariant, you're allowed to do the following: IEnumerable<string> strings = new List<string>(); IEnumerable<object> objects = strings;