I tried the following, and the result is in the interface names:
interface NotOK<out T>
{
bool TryDequeue(out T t);
}
interface OK<out T>
{
T TryDequeue(out bool b);
}
The docs have this to say:
ref and out parameters in C# cannot be variant.
Why a ref cannot be covariant (or contravariant, for that matter) is obvious, but why can out parameters not be covariant, the same way that method results are?
Is it a compiler limitation or could out parameters in fact break the covariance constraints?
My question actually had an answer already at ref and out parameters in C# and cannot be marked as variant
A relevant bit of Eric Lippert's great answer (but there's more):
Unfortunately no. "out" actually is not different than "ref" behind the scenes. The only difference between "out" and "ref" is that the compiler forbids reading from an out parameter before it is assigned by the callee, and that the compiler requires assignment before the callee returns normally. Someone who wrote an implementation of this interface in a .NET language other than C# would be able to read from the item before it was initialized, and therefore it could be used as an input. We therefore forbid marking T as "out" in this case. That's regrettable, but nothing we can do about it; we have to obey the type safety rules of the CLR.