using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace MyOverride { class Program { static void Main(string[] args) { person p1 = new person(); person p2 = new person("tom"); person p3 = new person("jim",20); Console.WriteLine("姓名:{0},年龄:{1}",p1.Name,p1.Age); Console.WriteLine("姓名:{0},年龄:{1}", p2.Name, p2.Age); Console.WriteLine("姓名:{0},年龄:{1}", p3.Name, p3.Age); Console.ReadLine(); }
} class person { public string Name { get; set; } public int Age { get; set; } public person() { this.Name = "未命名"; this.Age = 0; } public person(string name) { this.Name = name; } public person(string name, int age) { this.Name = name; this.Age = age; } } }
函数的重载,实际上就是函数的重名。指函数名称相同,但是函数的参数类型或者个数不同。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace MyOverride{ class Program {