Related question: Accessing a Class property without using dot operator
I’ve created a class called MyDouble looks like this
class MyDouble
{
double value;
//overloaded operators and methods
}
I am able to do all kinds of operations on MyDouble. Examples:
MyDouble a = 5.0;
a += 3.0;
...etc
However, this still throws an error
MyDouble a = 5.0;
long b = (Int64)a; //error
long b = (int64)a.value; //works
How can I define it such that an operation like (Int64)a automatically converts to (Int64)a.value ? I don’t want the user to ever have to worry about the existence of the value property.
In order for this conversion to work, you would need an explicit conversion to Int64.
This would look like: