Operators are overloaded, not overridden — in other words, choosing which implementation to use at compile time. The compiler only knows about T as a DataType , so it calls the statement in a DataType .
One option is to remove the statement from MyBool , but add a virtual method to the DataType , allowing polymorphic behavior:
public class DataType { public static explicit operator bool(DataType D) {
Please note that this will not work for converting from bool to DataType , as in this case we do not have information about which subtype of DataType you really want to create.
(Side note: your code will be easier to track if you used the usual .NET naming conventions.)
Jon skeet
source share