Custom operators overloading in C#
Forums:
class Point {
public double x;
public double y;
public Point(double x, double y) {
this.x = x;
this.y = y;
}
public static Point operator ^(Point p, int power) {
var x = Math.Pow(p.x, power);
var y = Math.Pow(p.y, power);
return new Point(x, y);
}
public static Point operator ^(Point p) {//<-Error
}
}
var p1 = new Point(2, 3);
p1 = p1 ^ 3;
//p1.x is 8 and p1.y is 27
- Log in to post comments