I have looked at similar questions, though my case seems to be different.
For this code:
public interface MyInterface<out T> {
bool TrySomething(out T val);
}
I get this error on C# 7.2:
Invalid variance: The type parameter 'T' must be invariantly valid on 'MyInterface.TrySomething(out T)'. 'T' is covariant.
Is this a bug, or am I missing something? I am not supplying the T
value here, I am getting it out (i.e. reading, hence the out
method parameter modifier in TrySomething
. So, why doesn't it compile?