-
Notifications
You must be signed in to change notification settings - Fork 0
/
OperatorOverloading.cs
52 lines (40 loc) · 1.13 KB
/
OperatorOverloading.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Diagnostics;
namespace TestApplication
{
/* Polymorphism --- Example of Operator Overloading ---
The concept of operating overloading a function can also apply to operators.
Operator overloading gives the ability to use the same operator to do various
operations.
*/
public class Program
{
private int _number1;
private int _number2;
public Program(int number1, int number2)
{
_number1 = number1;
_number2 = number2;
}
public static Program operator -(Program c1)
{
c1._number1 = -c1._number1;
c1._number2 = -c1._number2;
return c1;
}
public void Print()
{
Console.WriteLine("Number 1 = " +_number1);
Console.WriteLine("Number 2 = " +_number2);
}
}
internal static class Polymorphism
{
public static void Main(string[] args)
{
var program = new Program(15,-25);
program = -program;
program.Print();
}
}
}