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
Operator Overloading:
Using operator overloading we can change the meaning to the existing operator, All operator over-loading functions should be static, Using operator keyword we can over-load unary-operator and binary operators.
Example on Operator Overloading:
Start Microsoft Visual Studio - Click on file- New- Open New Project



You need to include this Overloading functions in Our Class Named "emp" as shown below
class emp
{
int ts;
//I am creating three functions using same name
public void tsal(int sal)
{
MessageBox.Show(sal.ToString(),"Salary");
}
public void tsal(int sal,int bonus)
{
ts = sal + bonus;
MessageBox.Show(ts.ToString(),"Salar+Bonus is ");
}
public void tsal(int sal, int bonus, int ta)
{
ts = sal + bonus + ta;
MessageBox.Show(ts.ToString(),"Salary+Bonus+ta is ");
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
//I am calling three functions using button click event
private void button1_Click(object sender, EventArgs e)
{
emp e1 = new emp();
int s, b, t;
s = 5000;
b = 300;
t = 200;
e1.tsal(s);
e1.tsal(s,b);
e1.tsal(s,b,t);
}
Coming to the Output Use f5
You see a window as shown below
Function Overloading
Using function overloading we can implement any no.of functions with the same name. by providing different prototypes or Arguments, While implement the function overloading we have to check only with function name and with the parameters, not with the return types.
Example on Function Over-loading
Start Microsoft Visual Studio - Click on file- New- Open New Project

Designtime Binding:
In the design time binding the total instructions we can give using design mode to the compiler the design time binding we can classify in to two types
- Function Overloading
- void tsal()
- void tsal(int s)
- void tsal(int s,int b)
- int tsal();
- Operator Overloading
- 10+20
- str+str
- obj+obj
Polymorphism :
The polymorphism is the concept of sharing and ability features to the multiple forms, The polymorphism. we can classify into two types
- Designtime Binding
- Runtime Binding
- virtual function




But right click the AssemblyInfo.cs tab at the top, and click Close from the menu. Now, in the Solution Explorer, click the plus symbol next to References:

Before we add some code, let's save the project. We'll do that in the next part below.
Previous Page