定义:List<数据类型> a = new List<数据类型>();
增加数据:a.Add("加入的数据");
static void Main(string[] args)
{
List<string> Ndate = new List<string>();
for (int i =0; i <3; i++)
{
string name = Console.ReadLine();
Ndate.Add(name);
}
for (int i = 0; i < Ndate.Count; i++)
{
Console.WriteLine(Ndate[i]);
}
Console.ReadKey();
}
可以将有可能报错的代码写进try catch语句内
try{ 可能报错语句; } catch{ 报错后执行的语句; console.ReadKey(); return; }
如果需要一直输入直到正确,可使用for循环
bool ischeck=true; for(;ischeck;){ try(){ 可能报错的语句; ischeck=false; } catch{ 报错后执行的语句; ischeck=true; } }