Can I create a class with a default return value? Lets say if I create an object of this class I get always a specific value, without calling the properties or something else. Example:
int i = new MyIntClass(/*something*/); //will return an int
Actually I would like to use a default function for returning something. Maybe like this:
class MyCalculator()
{
public double a { get; set; }
public double b { get; set; }
MyCalculator(double a, double b)
{
this.a = a;
this.b = b;
}
public double DoMath()
{
return a*b;
}
}
/* somewhere else */
double result = new MyCalculator(5.5, 8.7);
result should be the result of DoMath(). Is that possible? I know its maybe not the best example, but something like this would be nice. Any ideas?
You can do an implicit cast.
Example (add to class):