26. unary_operator_overloading
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace unary_operator_overloading.cs
{
class clsmath
{
int a, b;
clsmath(int a, int b)
{
this.a = a;
this.b = b;
}
public static clsmath operator -(clsmath m1)
{
m1.a = -m1.a;
m1.b = -m1.b;
return m1;
}
public void display()
{
Console.WriteLine("Value of A = " + a);
Console.WriteLine("Value of B = " + b);
}
}
class Program
{
static void Main(string[] args)
{
clsmath m1 = new clsmath(10, 20);
m1 = -m1;
m1.display();
Console.Read();
}
}
}
OUTPUT:
Value of A = -10
Value of A = -20
Comments
Post a Comment