重载,简单来说,就是函数或者方法有相同的名称,但是参数列表不相同的情形,这样的同名不同参数或者方法之间,互相称之为重载函数或者方法。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Student Steven = new Student("99","FUPU","男",Convert.ToDateTime("2001-2-18"),"18965428945","FUPU@168.com","翻斗大街翻斗花园2号楼1001室");
Student Steven1 = new Student("99", "FUPU", "男", Convert.ToDateTime("2001-2-18"), "18965428945", "FUPU@168.com");
Student Steven2 = new Student("99", "FUPU", "男", Convert.ToDateTime("2001-2-18"), "18965428945");
Student Steven3 = new Student("99", "FUPU", "男", Convert.ToDateTime("2001-2-18"));
Student Steven4 = new Student("99", "FUPU", "男");
Student Steven5 = new Student("99", "FUPU");
Steven.SayHello();
Console.ReadKey();
}
}
class Student
{
//属性
//学号
public string SNO { get; set; }
//姓名
public string SName { get; set; }
//性别
public string Gender{ get; set; }
//出生日期
public DateTime Birthday { get; set; }
//手机号码
public string MObile { get; set; }
//邮箱地址
public string Email { get; set; }
//家庭住址
public string HomeAddress { get; set; }
//方法
public void SayHello()
{
Console.WriteLine("大家好,我的学号是:{0}叫做{1},是一个{2}生,于{3}出生,手机号为{4},邮箱地址为{5},家住{6}",
SNO, SName, Gender, Birthday, MObile, Email, HomeAddress);
}
//构建方法:包含1个参数
public Student(string sno)
{
SNO = sno;
}
//构建方法:包含2个参数
public Student(string sno, string sname) : this(sno)
{
SName = sname;
}
//构建方法:包含3个参数
public Student(string sno, string sname, string gender):this(sno,sname)
{
Gender = gender;
}
//构建方法:包含4个参数
public Student(string sno, string sname, string gender, DateTime birthday):this(sno,sname,gender)
{
Birthday = birthday;
}
//构建方法:包含5个参数
public Student(string sno, string sname, string gender, DateTime birthday, string mobile):this(sno,sname,gender,birthday)
{
MObile = mobile;
}
//构建方法:包含6个参数
public Student(string sno, string sname, string gender, DateTime birthday, string mobile, string email) : this(sno, sname, gender, birthday,mobile)
{
Email = email;
}
//构建方法:包含7个参数
public Student(string sno, string sname, string gender,DateTime birthday,string mobile,string email,string homeaddress) : this(sno, sname, gender, birthday, mobile,email)
{
HomeAddress = homeaddress;
}
}
}