C# Program addition operator for Point -


i'm using c# xna , found when trying add 2 points won't let me. there way can add point class allow code run.

point = new point(3,4); point b = new point(6,2); point c = + b; //should equal new point(9,6); 

you overload + operator - this:

class point {     public int x { get; private set; }     public int y { get; private set; }      public point(int x, int y)     {         x = x;         y = y;     }      public static point operator +(point p1, point p2)     {         return new point(p1.x + p2.x, p1.y + p2.y);     } } 

now, code compiles work expect to:

point = new point(3, 4); point b = new point(6, 2); point c = + b; //should equal new point(9,6); - , :) 

more info on operator overloading can found on msdn.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -