阿牛 - 专注.NET开发

如果梦想与实现之间有一道不可逾越的鸿沟,那么“执行力”就是跨越这道鸿沟的桥梁。

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    
class MyCls
    
{
        
public int X
        
{
            
get;
            
set;
        }

        
public int Y
        
{
            
get;
            
set;
        }

        
public override string ToString()
        
{
            
return string.Format("X={0},Y={1}", X, Y);
        }

        
public override bool Equals(object obj)
        
{
            MyCls a 
= obj as MyCls;

            
return a.X == this.X && a.Y == this.Y;
        }

        
public override int GetHashCode()
        
{
            
return X * Y;
        }
      
        
public static MyCls operator +(MyCls a, MyCls b)
        
{
            
return new MyCls() { X = a.X + b.X, Y = a.Y + b.Y };
        }

        
public static MyCls operator -(MyCls a, MyCls b)
        
{
            
return new MyCls { X = a.X - b.X, Y = a.Y - b.Y };
        }

        
public static MyCls operator ++(MyCls a)
        
{
            
return new MyCls() { X = a.X++, Y = a.Y++ };
        }

        
public static MyCls operator --(MyCls a)
        
{
            
return new MyCls() { X = a.X--, Y = a.Y-- };
        }

        
public static bool operator ==(MyCls a, MyCls b)
        
{
            
return a.X == b.X && a.Y == b.Y;
        }

        
public static bool operator !=(MyCls a, MyCls b)
        
{
            
return a.X != b.X && a.Y != b.Y;
        }

        
public static void Main()
        
{
            MyCls a 
= new MyCls { X = 1, Y = 1 };
            MyCls b 
= new MyCls { X = 2, Y = 2 };
            Console.WriteLine(a 
+ b);
            Console.WriteLine(b 
- a);
            Console.WriteLine(b
++);
            Console.WriteLine(a
--);
            Console.WriteLine(a
++ == b);
            Console.WriteLine(a
!= b--);
            Console.ReadLine();
        }

    }

}


 

输出结果:

X=3,Y=3
X=1,Y=1
X=3,Y=3
X=0,Y=0
True
False

 

posted on 2008-05-25 13:24  阿牛-专注金融行业开发  阅读(418)  评论(1编辑  收藏  举报