using System;
namespace ConsoleHide {
class Program {
static void Main(string[] args) {
Cat[] cats = { new Cat("十五"),new Cat("十六")};
for (int i=0;i<cats.Length; i++) {
cats[i]++;
cats[i].PrintCatAge();
}
}
}
public class Cat {
public int age;
public string name;
public Cat(string nameTemp) {
age = 0;
name = nameTemp;
}
public static Cat operator ++(Cat cat) {
++cat.age;
return cat;
}
public void PrintCatAge() {
Console.WriteLine(name+" "+age);
}
}
}
C#运算符重载
最新推荐文章于 2023-11-15 11:01:15 发布