这是我的代码:
public class GoodSuperDictionary
{
private Dictionary<string, string> dicitionary;
public GoodSuperDictionary(Dictionary<string, string> dic)
{
dicitionary = dic;
}
public static explicit operator GoodSuperDictionary(Dictionary<string, string> dic)
{
return new GoodSuperDictionary(dic);
}
}
Dictionary<string, string> dic = new Dictionary<string, string>();
GoodSuperDictionary dic2 = dic as GoodSuperDictionary; // compile error
GoodSuperDictionary dic3 = (GoodSuperDictionary)dic; // good
我希望compile error
行能够运行,但似乎explicit operator
并没有处理这种投射。
我想知道为什么会这样?
我还想知道operator
是否允许as
投射进入?