简体   繁体   English

c#中代表的内容和内容是什么?

[英]What is in and out on delegate in c#?

In c# code, i found this implement. 在c#代码中,我发现了这个工具。

I tried to find out what this in and out meaning, but only explanation of out keyword in there. 我试图找出这个内外意义,但只解释了那里的关键字。

So what these in and out keyword do? 那么这些进出关键字的作用是什么?

public delegate Tb Reader<in Ta, out Tb>( Ta a );

The in parameter specifies that the type parameter is contravariant -you can pass in a class that Ta inherits from. in参数指定类型参数是逆变的 - 您可以传入Ta继承的类。

The out parameter specifies that the parameter is covariant -> you can use more derived types. out参数指定参数是协变的 - >您可以使用更多派生类型。

See here for the in modifer, and here for the out modifier 这里的在改性剂,并在这里对出修改

They make possible to do like below example. 他们可以像下面的例子那样做。

Reader<string,object> first = someString => return someObject;
Reader<object,string> second= someObject => return someString;
first=second;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM