Can someone please explain why the position of Type parameters used in Interface swaps while in Func delegates as method parameters for Interface method
To be precise I am having issue understanding reason behind this
interface IMyInterface<out Tout, in TIn>{
public TOut ShowT();
public void AddT2(TIn t2);
Action<TIn> Action();
public TOut MyIMethod(Func<TOut, TIn> func);
public void SeeAction(Action<TOut> action);
}
The last two method makes me more than confused and could not understand despite knowing rules for covariant and contravariant.
Please someone explain why position of TOut and TIn get swapped while using Func<> and Action<> delegate in method parameter, as we know that Tout is covariant and TIn as contravariant,
I have seen numerous examples in StackOverflow but could not understand.
NOTE: Please don't suggest "Exact rules for Variance", I have read that dozen times only to let it off pass my head without understanding.
Some simple example with do the trick Also please refer some materials related to .NET Generics.
I already have gone through few topics on internet like
- Exact rules for variance
- Covariance and Contravariance with Func in generics
- Microsoft's documentation also covered but that doesn't have too depth to make critical part understandable (they didn't put much effort).
- Read books like C# in depth, essential C#, Professional .NET 2.0 Generics by Tod Golding, etc
Please help me out of this nefarious situation