我是C#的初学者,我有一项任务是创建一个程序来对两个数组进行排序,并根据用户颜色输入找到最大的鱼。我不知道如何使它工作。任何人都可以给我一些指示吗?这是我到目前为止所拥有的。
Console.WriteLine("Select a fish color. \nEnter only the number.\n1.
Black\n2. Green\n3. Red\n4. Blue\n5. Yellow\nEnter Your Selection:");
string userColor = Console.ReadLine();
int value;
while (!(int.TryParse(userColor, out value) && value >=1 && value <=5))
{
Console.WriteLine("Please type only numbers from 1 to 5");
userColor = Console.ReadLine();
}
int color = int.Parse(userColor);
string[] colors = new string[] { "Black", "Black", "Green", "Red", "Blue", "Yellow", "Black", "Green", "Red", "Blue", "Yellow", "Black", "Green", "Red", "Blue","Yellow"};
double[] lenght = new double[] { 8.5, 9.8, 10.9, 40, 36, 45, 43, 12, 17.8, 13.5, 14.9, 27.7, 26.9, 50, 60,13 };
Console.WriteLine("You chose " + colors[color]);
Console.WriteLine("The biggest " + colors[color] + " fish is " + lenght[color]+ " inches long.");
答案 0 :(得分:0)
所以,你需要做两件事:
我会尝试给你一个开始的地方,以及你可能使用的工具的一个例子:
for
循环,因为这样可以让您轻松遍历两个列表中的值。==
比较鱼的颜色。(PS我故意保持模糊和新手友好。如果我为自己解决这个问题,我可能会尝试找到一种方法来解决2-3行中的这个问题,但这需要比你更多的理解到目前为止。)