5

In c# code, i found this implement.

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 );
JaeWoo So
  • 568
  • 5
  • 18

2 Answers2

3

The in parameter specifies that the type parameter is contravariant -you can pass in a class that Ta inherits from.

The out parameter specifies that the parameter is covariant -> you can use more derived types.

See here for the in modifer, and here for the out modifier

Rodrick Chapman
  • 5,437
  • 2
  • 31
  • 32
Kolichikov
  • 2,944
  • 31
  • 46
-1

They make possible to do like below example.

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