This question already has answers here:
still confused about covariance and contravariance & in/out
                                
                                    (6个答案)
                                
                        
                                5年前关闭。
            
                    
public delegate TOutput Converter<in TInput, out TOutput>(TInput input)


此声明中inout是什么意思?

最佳答案

这是Eric Lippert博客中的一篇很棒的文章,解释了in和out关键字。它们用于表示泛型类型参数中的协方差和反方差。

What's the difference between covariance and assignment compatibility?

在C#4成为Covariance和Contravariance的功能之前,他还撰写了一篇由11部分组成的系列文章。我强烈建议您阅读它们,因为它们确实可以帮助您理解这些概念。

我刚刚检查了一下,并且它们没有相互链接(并且没有简单的方法可以直接链接到我可以找到的系列),所以这里有一个目录。

C#中的协方差和协方差


Part One
Part Two: Array Covariance
Part Three: Method Group Conversion Variance
Part Four: Real Delegate Variance
Part Five: Higher Order Functions Hurt My Brain
Part Six: Interface Variance
Part Seven: Why Do We Need A Syntax At All?
Part Eight: Syntax Options
Part Nine: Breaking Changes
Part Ten: Dealing With Ambiguity
Part Eleven: To infinity, but not beyond

10-04 19:08