Why doesn't C # allow implicit reference conversions from interface type to class?

Given:

public class T 
{
    public static implicit operator T(R r)
    {
        return new T();
    }
}

public class S: R { }
public class R { }

      

If R is an interface, the code will not compile:

custom conversions to or from the interface are not allowed

Interfaces are essentially public / inner classes with all public members and no implementation. So what is the purpose of this limitation?

+3
c #


source to share


No one has answered this question yet

See similar questions:

22
Why can't I use an explicit operator interface?

or similar:

1270
Why not inherit from List <T>?
612
C # interfaces. Implicit implementation versus explicit implementation
432
Why doesn't C # allow static methods to implement an interface?
358
If my interface needs to return Task, what is the best way to implement it without an operation?
322
Why should we define both == and! = In C #?
52
Why would the implicit conversion operator from <t> <u> accept </u> <T?> <u>? </u>
21
Interfaces, Inheritance, Implicit Operators and Type Conversions, why is this?
6
Why doesn't C # allow types that use composition to have implicit conversions for interfaces?
five
Implicit error converting references between a specific interface type
1
Implicit conversion not assigned to interface



All Articles
Loading...
X
Show
Funny
Dev
Pics