随笔分类 - 泛型
摘要:问题: When planning out my programs, I often start with a chain of thought like so: A football team is just a list of football players. Therefore, I sho
阅读全文
摘要:IComparable<Student>是Student的父类,所以IComparable<Student>可以接收Student。但是在使用CompareTo方法的时候,必须传入Student,不允许传入父类IComparable<Student>。 public interface ICompa
阅读全文
摘要:Define class with itself as generic implementation. Why/how does this work? 问题: I've normally been creating Prism Events used by the EventAggregator l
阅读全文
摘要:variance差异 变异;变化;不一致;分歧;[数] 方差 convariance协变 仅仅用于返回值,范围扩大 out contra相反 contravariance逆变 仅仅用于函数参数,范围缩小 in 引入 https://www.codewars.com/kata/unflatten-a-
阅读全文
摘要:https://msdn.microsoft.com/zh-cn/library/ee378665(v=vs.110).aspx 此方法有一共有2个,现在只讨论其中一个 public TValue AddOrUpdate( TKey key, TValue addValue, Func<TKey,
阅读全文
摘要:上面示例中的Farm<T>类以及本章前面介绍的其他几个类都继承自一个泛型类型。 在Farm<T>中,这个类型是一个接口IEnumerable<T>。 这里Farm<T>在T上提供的约束也会在IEnumerable<T>中使用的T上添加一个额外的约束。 这可以用于限制未约束的类型,但是需要遵循一些规则
阅读全文
摘要:这种错误的原因,是因为List<T>不是线程安全的。
阅读全文
摘要:Covariance and Contravariance (C#) https://docs.microsoft.com/en-us/dotnet/articles/csharp/programming-guide/concepts/covariance-contravariance/ In C#
阅读全文