See docs
https://learn.microsoft.com/en-us/dotnet/standard/generics/covariance-and-contravariance
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Some languages (e.g., Eiffel), accept covariant method argument redefinition and employ some other mechanisms to address type safety issues that arise in this case. When I tried to mimic this in C#, I get a compile-time error. Doing the same in plain IL successfully passes compilation, but causes a run-time error. In both cases (compile-time error for C# and run-time error for IL), the message says that the covariant method argument type (I used a generic parameter with a covariant type mark) cannot be covariant for type safety reasons.
When generics were introduced, the design paper claimed that covariant generics are supported to enable different programming languages, although in non-verifiable .NET code. Is it still the case, or was the idea of supporting languages with non-C# type systems abandoned? In particular, is there any mechanism (e.g., some attributes) to prevent .NET run-time from verification of arguments with covariant types until execution?