using System; using System.Collections; using System.Collections.Generic; namespace codeTest { class Program { static void Main(string[] args) { // C#的静态多态主要是通过overload来实现,主要有方法的重载和运算符的重载 A _A1 = new A() { number = 11 }; A _A2 = new A() { number = 21 }; _A1.SaidHello(); _A1.SaidHello(" World"); Console.WriteLine((_A1 + _A2).number); //C# 的动态多态主要通过 override 重写来实现 Human _humman1 = new Man(); Human _humman2 = new Woman(); _humman1.Run(); _humman2.Run(); Console.ReadLine(); } } class A { public int number { get; set; } public static A operator +(A a1, A a2) { A sum = new A(); sum.number = a1.number + a2.number; return sum; } public void SaidHello() { Console.WriteLine("Hello"); } public void SaidHello(string toWho) { Console.WriteLine(string.Format("Hello {0}", toWho)); } } class Human { public virtual void Run() { Console.WriteLine("human Run!"); } } class Man : Human { public override void Run() { Console.WriteLine("Man Run!"); } } class Woman : Human { public override void Run() { Console.WriteLine("Woman Run!"); } } }