Skip to content
Discussion options

You must be logged in to vote

First, as a remnant from the days before Generics, foreach statement generates explicit casts.

https://github.com/dotnet/csharpstandard/blob/draft-v8/standard/statements.md#13952-synchronous-foreach

And converting a class to an interface results in an error only when the class is sealed.

https://github.com/dotnet/csharpstandard/blob/draft-v8/standard/conversions.md#1035-explicit-reference-conversions

var a = (IA)new A(); // A derived class may implement the interface.
var a1 = (IA)new A1();

var b = (IA)new B(); // Error only when the class is sealed

interface IA;
class A;
class A1 : A, IA;
sealed class B;

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@newpost
Comment options

Answer selected by jnm2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants