大家都知道引用类型是不能直接相加的,要想相加就要进行重载,并且还要在操作符前加上关键字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;

  }

}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2021-11-03
猜你喜欢
  • 2022-12-23
  • 2022-01-01
  • 2021-12-08
  • 2021-06-21
  • 2021-09-28
相关资源
相似解决方案