I need to return a method in an operator function.
public int Add()
{
return 1;
}
public static int operator +()
{
return Add;
}
I will need to do this for a multiply, subtract and divide operator/function too.
Thanks
You can’t declare parameterless operators. You can declare an operator to return an appropriate delegate – e.g.
Func<int>– but it would be a pretty odd thing to do, IMO.If you can tell us more about what you’re trying to achieve, we can probably help you to work out a cleaner design.
Here’s a pretty strange example overloading the unary + operator:
EDIT: If you’re just trying to implement a
Rationaltype, you’re more likely to want: