Overload > and : Relotional Operator Overload : Operator Overload C# Examples


C# Examples » Operator Overload » Relotional Operator Overload »

 

Overload > and









    
using  System;    
    
class  TwoDimension  {    
    int  x,  y;
    
    public  TwoDimension()  {  
          x  =  y  =  0;  
    }    
    public  TwoDimension(int  i,  int  j)  {  
          x  =  i;  
          y  =  j;
    }    
    
    //  Overload  <.    
    public  static  bool  operator  <(TwoDimension  op1,  TwoDimension  op2)    
    {    
        if((op1.x  <  op2.x)  &&  (op1.y  <  op2.y))    
            return  true;    
        else    
            return  false;    
    }    
    
    //  Overload  >.    
    public  static  bool  operator  >(TwoDimension  op1,  TwoDimension  op2)    
    {    
        if((op1.x  >  op2.x)  &&  (op1.y  >  op2.y))    
            return  true;    
        else    
            return  false;    
    }    
    
    //  Show  X,  Y
    public  void  show()    
    {    
        Console.WriteLine(x  +  ",  "  +  y);    
    }    
}    
    
class  TwoDimensionDemo  {    
    public  static  void  Main()  {    
        TwoDimension  a  =  new  TwoDimension(5,  6);    
        TwoDimension  b  =  new  TwoDimension(10,  10);    
        TwoDimension  c  =  new  TwoDimension(1,  2);    
    
        Console.Write("Here  is  a:  ");    
        a.show();    
        Console.Write("Here  is  b:  ");    
        b.show();    
        Console.Write("Here  is  c:  ");    
        c.show();    
        Console.WriteLine();    
    
        if(a  >  c)  Console.WriteLine("a  >  c  is  true");    
        if(a  <  c)  Console.WriteLine("a  <  c  is  true");    
        if(a  >  b)  Console.WriteLine("a  >  b  is  true");    
        if(a  <  b)  Console.WriteLine("a  <  b  is  true");    
    }    
}
    
   
  
   



Output

Here is a: 5, 6
Here is b: 10, 10
Here is c: 1, 2

a > c is true
a 


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Operator Overload
» Relotional Operator Overload