3

Given:

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

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

If R were an interface, the code would not compile:

user-defined conversions to or from an interface are not allowed

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

4

0 回答 0