关于枚举中的基本加循环嵌套
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 定义
{
public enum Xb
{
男,
女
}
public struct Person
{
public String name;
public Xb a;
public int age;
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入你们班的人数");
int i = Convert.ToInt32(Console.ReadLine());
int zong = 1;
while (zong <= i)
{
Console.WriteLine("请第{0}个同学输入你的信息", zong);
Person onePerson;
Console.WriteLine("请输入你的姓名");
onePerson.name = Console.ReadLine();
do
{
try
{
Console.WriteLine("请输入你的年龄");
onePerson.age = Convert.ToInt32(Console.ReadLine());
break;
}
catch
{
Console.WriteLine("年龄只能输入正整数,请重新输入");
}
} while (true);
do
{
try
{
Console.WriteLine("请输入你的性别");
onePerson.a = (Xb)(Enum.Parse(typeof(Xb), (Console.ReadLine())));
break;
}
catch
{
Console.WriteLine("你输入的有误,请重新输入!");
}
} while (true);
zong++;
Console.WriteLine("第{0}位同学姓名叫{1},(他/她)今年{2}岁了,(他/她)是一位{3}孩", zong - 1, onePerson.name, onePerson.age, onePerson.a);
}
Console.WriteLine("程序结束");
Console.ReadKey();
}
}
}
