我打算制作一个将学生姓名按字母顺序排序的程序,我想要达到的结果的是让用户可以给string赋值,请问要如何操作?
Console.WriteLine("您的班级里有多少名学生?");
Console.ReadLine();
Console.WriteLine("请输入学生们的姓名");
string[] 姓名 = new string[];
for (int i = 0; i < 姓名.Length; i++)
{
姓名[i] = Console.WriteLine();
}
Console.WriteLine("现在他们已经按字母顺序排序了");
for (int i = 0; i < 姓名.Length; i++)
{
Console.WriteLine(姓名[i]);
}
Console.ReadKey();
P.S:我今天才开始学编程,希望这个问题没有让你感到比较无语
string[] 姓名 = new string[]; 你这个地方是创建一个string数组,但是并没有指定大小。所以下面的for循环不会执行。你需要对数组进行初始化。
如 string a[10]={};
string[] 姓名 = new string[];
你这语法都是错的呀
你需要给它一个长度,这样:
string[] 姓名 = new string[10];