Why can't I convert from 'out BaseClass' to 'out DerivedClass'?

With out parameters the argument is passed by reference just like ref, the difference is that the value must be assigned by the end of the method and the reference does not need to be initialized before calling. But it can be initialized before and the method can read the initial value.

enter image description here

From the docs: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/out-parameter-modifier

The out keyword causes arguments to be passed by reference

It is like the ref keyword, except that ref requires that the variable be initialized before it is passed

As the method can read the variable, the reference must be of type string to work. The reading blocks covariance and the output blocks contravariance, thus the argument must be invariant.

Tags:

C#

Out