三、代码示例
//author---Henan University.software engineering.李思佳
using System;
namespace ConsoleApp3
{
public enum Gender
{
男,
女
}
public class Citizen
{
public string ID { set; get; }
public string Name { set; get; }
public Gender G { set; get; }
public int Age;
public string Birthplace { set; get; }
public string Familyaddress { set; get; }
public int AGE //属性
{
get
{
return Age;
}
set
{
if (value <= 0 || value > 150)
Console.WriteLine("您输入的年龄不合法!(将修改为默认值)");
else
Age = value;
} //set
}//age
public Citizen()
{
ID = "0000";
Name = "xxx";
G = Gender.男;
Age = 20;
Birthplace = "xx省xx市";
Familyaddress = "xx省xx市";
}
public void Input(string id,string name,Gender g,int age,string birthplace,string familyaddress)
{
ID = id;
Name = name;
G = g;
AGE = age;
Birthplace = birthplace;
Familyaddress = familyaddress;
}
public void Print()
{
Console.WriteLine("该公民的信息如下:");
Console.WriteLine("身份证号:" + ID);
Console.WriteLine("姓名:" + Name);
Console.WriteLine("性别:" + G);
Console.WriteLine("年龄:" + Age);
Console.WriteLine("籍贯:" + Birthplace);
Console.WriteLine("家庭住址:" + Familyaddress);
}
}
class Program
{
static void Main(string[] args)
{
Citizen c0 = new Citizen();
Console.WriteLine("the example person:");
c0.Print();
Console.WriteLine("");
Citizen c1 = new Citizen();
Console.WriteLine("the first person:");
c1.Input("412825", "lisi", Gender.女, 18, "河南省", "河大");
c1.Print();
Console.WriteLine("");
Citizen c2 = new Citizen();
Console.WriteLine("the second person:");
c2.Input("412826", "zhangsan", Gender.男, -1, "河南省", "郑大");
c2.Print();
Console.WriteLine("......");
Console.ReadLine();
}
}
}



