true and false operator : True false operator : Operator Overload C# Examples


C# Examples » Operator Overload » True false operator »

 

true and false operator









    
using  System;

        public  class  MyType
        {
                public  static  bool  operator  true  (  MyType  e  )
                {
                        return    (  e  ==  null  )  ?  false  :  e.b;
                }

                public  static  bool  operator  false  (  MyType  e  )
                {
                        return    (  e  ==  null  )  ?  true  :  !e.b;
                }

                public  bool  b;

                public  MyType(  bool  b  )
                {
                        this.b  =  b;
                }

                public  static  void  Main(  string[]  args  )
                {
                        MyType  myTrue  =  new  MyType(  true  );
                        MyType  myFalse  =  new  MyType(  false  );
                        MyType  myNull  =  null;

                        if  (  myTrue  )
                        {
                                System.Console.WriteLine(  "true"  );
                        }
                        else
                        {
                                System.Console.WriteLine(  "false"  );
                        }

                        if  (  myFalse  )
                        {
                                System.Console.WriteLine(  "true"  );
                        }
                        else
                        {
                                System.Console.WriteLine(  "false"  );
                        }

                        if  (  myNull  )
                        {
                                System.Console.WriteLine(  "true"  );
                        }
                        else
                        {
                                System.Console.WriteLine(  "false"  );
                        }
                }
        }
    
   
  
   



Output

true
false
false


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Operator Overload
» True false operator