【发布时间】:2021-02-14 07:03:05
【问题描述】:
在我的程序中,我必须取 7 个名字并按字母顺序显示它们。但我得到了错误
错误 CS0029:无法将类型“字符串”隐式转换为“整数”
我做错了什么?
代码:
static void Main(string[] args)
{
int size = 7;
int[] people = new int[size];
for(int i = 0; i < size; i++)
{
Console.WriteLine("Please enter " + i+1 + ". person's name: ");
// Here
people[i] = Console.ReadLine();
}
Console.WriteLine("After alphabetic ordering: ");
Array.Sort(people);
for (int j = 0; j < size; j++)
{
Console.WriteLine(j + 1 + "person's name : " + people[j]);
}
// ...
}
【问题讨论】:
-
想一想:您正在尝试将字符串形式的人名存储到整数数组中。
-
更改自:int[] people = new int[size]; To : string[] people = new string[size];
标签: c# windows-console