class operatordemo
{
int a, b;
string s1, s2;
public operatordemo()
{
a = 10; b = 20; s1 = "csharp"; s2 = ".net";
}
public static int operator +(operatordemo r1, operatordemo r2)
{
int tot;
string str;
str = r1.s1 + r2.s2;
tot = r1.a + r2.b;
MessageBox.Show(str);
return tot;
}
}
private void button1_Click(object sender, EventArgs e)
{
operatordemo obj1 = new operatordemo();
operatordemo obj2 = new operatordemo();
int t;
t = obj1+obj2;
MessageBox.Show(t.ToString());
}
Press F5 and you see this Outputs


First Page in Operator Overloading
Comments (0)
Post a Comment