class Program
{
static void Main(string[] args)
{
int i = 0;
string strName = "";
string stId = "";
string ages = "";
Student[] stus = new Student[5];
Console.WriteLine("请输入学员信息:");
for (i = 0; i < stus.Length; i++)
{
Console.WriteLine("请输入第{0}个学员的姓名:", i + 1);
stus[i] = new Student();
while (true)
{
Console.Write("姓名:");
strName = Console.ReadLine();
stus[i] = new Student();
if (stus[i].setStuName(strName))
{
break;
}
else
{
Console.WriteLine("您输入的学员姓名不正确!");
}
}
while (true)
{
Console.Write("ID:");
stId = Console.ReadLine();
stus[i] = new Student();
if (stus[i].setStuId(stId))
{
break;
}
else
{
Console.WriteLine("你输入的学号不正确!");
}
}
while (true)
{
Console.Write("年龄:");
ages = Console.ReadLine();
stus[i] = new Student();
if (stus[i].setStuAge(ages))
{
break;
}
else
{
Console.WriteLine("你输入的年龄错误!");
}
}
}
for (int x = 0; x < stus.Length; x++)
{
stus[x].showStuInfo(stus[x].stuId, stus[x].stuName, stus[x].stuAge);
}
}
class Student
{
public int stuId;
public string stuName;
public int stuAge;
public Student()
{
stuId = 0;
stuName = "";
stuAge = 0;
}
/// <summary>
/// 显示学员信息
/// </summary>
public void showStuInfo(int _id, string _name, int _age)
{
Console.WriteLine("{0}+{1}+{2}", _id, _name, _age);
}
/// <summary>
/// 设置学员ID
/// </summary>
/// <param name="_id">必须是小于100的正整数</param>
/// <returns></returns>
public bool setStuId(string _id)
{
int value = int.Parse(_id);
if (value > 0 && value < 100)
{
stuId = value;
return true;
}
else
{
return false;
}
}
/// <summary>
/// 设置学员姓名
/// </summary>
/// <param name="_name">不能为空,不能为admin</param>
/// <returns></returns>
/// if (stus[i].setStuName(strName))
public bool setStuName(string _name)
{
if (_name == "" || _name == "admin")
{
return false;
}
else
{
stuName = _name;
return true;
}
}
/// <summary>
/// 设置学员的年龄
/// </summary>
/// <param name="_age">必须在18-60(含)之间</param>
/// <returns></returns>
public bool setStuAge(string _age)
{
int value = int.Parse(_age);
if (value >= 18 && value <= 60)
{
stuId = value;
return true;
}
else
{
return false;
}
}
}
萧十郎
杨魅力
犯罪嫌疑人X