c# - 了解 C# 4.0 中的协变和逆变

标签 c# .net covariance contravariance

我在第 9 channel 看了一段关于它的视频,但我并没有真正理解它。

有人可以给我一个简单易懂的例子吗?在那之后可能如何在实践中使用它?

最佳答案

你可能想看看这个博客,他解释得很好,但我认为需要更多的例子来为人们澄清,因为这进入了一个非常难以理解的领域,但是,文章下面的引述很好地总结了这一点。

http://hestia.typepad.com/flatlander/2008/12/c-covariance-and-contravariance-by-example.html

"covariance and contravariance" means that you can now pass inexact generic types when it's safe to do so, just as you can pass inexact argument types when it's safe to do so.

关于c# - 了解 C# 4.0 中的协变和逆变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1724919/

相关文章:

c# - Process.Start() 和进程树

c# - 中止 .NET 线程

python - 如何在 Python 中获取 n 个数组的 n x n 协方差矩阵?

c# - 如何将 IEnumerable<?> 转换为 IEnumerable<string>?

c# - 在以下情况下使用静态方法访问数据库是否安全

c# - 在 Wow6432Node 中写入注册表值而不重定向

c# - 使用附加文本对 C# 中的标签进行数据绑定(bind)?

.net - lightswitch vs2012 中的表单例份验证

c# - 在代码隐藏中添加 ListBoxItems

scala - 如何确定类型参数的方差?