using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _1.自定义 { class Program { static void Main(string[] args) { MyFriden lily = new MyFriden(); lily.Age = 10; MyFriden lucy = new MyFriden(); lucy.Age = 20; int ageSum = lily + lucy; Console.WriteLine(ageSum); Console.Read(); } ///// <summary> ///// 操作符的覆盖 ///// </summary> ///// <returns></returns> //public static int operator +(int n, int m) //{//不可以这样,太不安全了,微软不会给我们这样的权限的 // return n + m; //} /// <summary> /// 两个人的年龄和 /// </summary> /// <returns></returns> /// <summary> /// 朋友类 /// </summary> public class MyFriden { public int Age { get; set; } public static int operator +(MyFriden a, MyFriden b) { return a.Age + b.Age; } } } }