using System;
class Complex
{
private int x;
private int y;
public Complex()
{
}
public Complex(int i, int j)
{
x = i;
y = j;
}
public void ShowXY()
{
Console.WriteLine(\"{0} {1}\",x,y);
}
public static Complex operator +(Complex c1,Complex c2)
{
Complex temp = new Complex();
temp.x = c1.x+c2.x;
temp.y = c1.y+c2.y;
return temp;
}
}
class MyClient
{
public static void Main()
{
Complex c1 = new Complex(10,20);
c1.ShowXY(); // displays 10 & 20
Complex c2 = new Complex(20,30);
c2.ShowXY(); // displays 20 & 30
Complex c3 = new Complex();
c3 = c1 + c2;
c3.ShowXY(); // dislplays 30 & 50
}
}
}
}
How anybody explain to me how this work. I know I have been keeping asking questions, which seems a bit annoying to someone. But I really want to learn.
Well what bugs me is when it comes to the parameter of the overloaded method, and I am just wondering:
1) What value it takes as a parameter to work with? Is it an object or something else?
2) What method calls send the arguments to the parameter of the overloaded object?
3) And when the overloaded method returns the value, where or to which the value is being retured?
4) Does it have anything to do with the constructors?
What I know is only the parameter of the overloaded method consists of the operands you might wanna work with. And hope I am not being felt annoying.

New Topic/Question
Reply




MultiQuote





|