操作符的重载问题

大家都知道引用类型是不能直接相加的,要想相加就要进行重载,并且还要在操作符前加上关键字operator ,下面我简单的实现下‘+’的重载。

主要代码:

public class Person

{

  private int weight;

  public int Weight

  {

    get{return weight;}

    set{weight = value;}

  }

}

 

public class Test

{

  static int operator +(Person A, Person B)

  {

    return A.Weight + B.Weight;

  }

}

posted @ 2010-06-24 16:31  JasonNET  阅读(165)  评论(0编辑  收藏  举报