Is there a way to use operators as functions without declaring them manually?
Func<bool, bool> not = x => !x;
Similar to (+)/(-) in Haskell. Would be handy in various LINQ scenarios involving conditional query construction. Maybe some C# (4.0+) trick I don’t know about.
Edit: here is a sample to clarify what I mean:
int MyWhere(Func<bool, bool, bool> cond) {}
a usual call would be:
MyWhere((x,y) => x && y)
a cool call would be (assuming Haskell style):
MyWhere((&&))
No.
You can find the definitions (F12 in VS) for the operators you can overload, and there exists a
But there is no way to call
Double.operator==(a, b).The Framework does offer a
a.Equals(b)for this particualr case, but there is noa.Add(b).