為啥這個x會報錯啊
using System;
using System.Collections.Generic;
using System.Text;
namespace projGetMaxScore
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? int i,max,x;
? ? ? ? ? ? string[] names = new string[8] { "吳松", "錢東宇", "伏晨", "陳陸", "周蕊", "林日鵬", "何昆", "關欣"};
? ? ? ? ? ? int[] values = new int[8] { 89, 90, 98, 56, 60, 91, 93, 85 };?
? ? ? ? ? ? for(i = 0; i < values.Length; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? max = values[i];
? ? ? ? ? ? ? ? if (values[i] > max)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? max = values[i];
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? x = i;
? ? ? ? ? ? }
? ? ? ? ? ? Console.WriteLine(names[x]);
? ? ? ? }
? ? }
}
2022-07-11
int i, max=0, x=0;
? ? ? ? ? ? string[] names = new string[8] { "吳松", "錢東宇", "伏晨", "陳陸", "周蕊", "林日鵬", "何昆", "關欣" };
? ? ? ? ? ? int[] values = new int[8] { 89, 90, 98, 56, 60, 91, 93, 85 };
? ? ? ? ? ? for (i = 0; i < values.Length; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (values[i] > max)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? max = values[i];
? ? ? ? ? ? ? ? ? ? x = i;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? Console.WriteLine(names[x]);
2022-07-11
x沒有初始化啊,編譯的時候就會報錯,因為系統(tǒng)在運行之前不知道name【x】里面的x會被賦值的