J
Jon Shemitz
Why is the cast in Child.Test valid and the cast in Base.Test is not?
"C# Language Specification" section 6.4.4 makes me think that perhaps
the Base.Test cast is ambiguous in some way, but I don't see it. I'd
expect an implicit conversion of Value to long, Derived.Derived() to
turn that into a Derived, then an implicit child-to-parent conversion
of that to Base.
What am I missing?
class Parent
{
public static explicit operator float (Parent Instance)
{
return 1f; // just to return something
}
}
class Child: Parent
{
static void Test()
{
Child Instance = new Child();
double D = (double) Instance; // OK
}
}
class Base
{
static void Test()
{
int Value = 1;
Base Instance = (Base) Value; // Not
}
}
class Derived: Base
{
public static explicit operator Derived(long Value)
{
return new Derived();
}
}
"C# Language Specification" section 6.4.4 makes me think that perhaps
the Base.Test cast is ambiguous in some way, but I don't see it. I'd
expect an implicit conversion of Value to long, Derived.Derived() to
turn that into a Derived, then an implicit child-to-parent conversion
of that to Base.
What am I missing?
class Parent
{
public static explicit operator float (Parent Instance)
{
return 1f; // just to return something
}
}
class Child: Parent
{
static void Test()
{
Child Instance = new Child();
double D = (double) Instance; // OK
}
}
class Base
{
static void Test()
{
int Value = 1;
Base Instance = (Base) Value; // Not
}
}
class Derived: Base
{
public static explicit operator Derived(long Value)
{
return new Derived();
}
}