運行顯示 無法將類型string 隱式轉(zhuǎn)換為int
string[]names={"吳松","錢東宇","伏晨","陳陸","周蕊","林日鵬","何昆","關欣"};
? ? ? ? ? int[]scores={"89","90","98","56","60","91","93","85"};
? ? ? ? ? for(int i=0; i<scores.Length; i++)
? ? ? ? ? {
? ? ? ? ? ? ? int max=0;
? ? ? ? ? ? ? int b=0;
? ? ? ? ? ? ? if (scores[i]>max)
? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? max= scores[i];
? ? ? ? ? ? ? ? ? b=i;
? ? ? ? ? ? ? ? ? Console.WriteLine("分數(shù)最高的是{0},分數(shù)是{1}",names[i],scores[i]);
? ? ? ??
? ? ? ? ? ? ? }
? ? ? ? ? }
2018-07-27
? ? ? ? ? ? string[,] result = new string[8, 2] { { "吳松", "89" }, { "錢東宇", "90" }, { "伏晨", "98" }, { "陳陸", "56" }, { "周蕊", "60" }, { "林日鵬", "91" }, { "何昆", "93" }, { "關欣", "85" } };
? ? ? ? ? ? int x = int.Parse(result[0,1]),y;
? ? ? ? ? ? for (int i = 0; i<result.GetLongLength(0);i++)
? ? ? ? ? ? {? ??
? ? ? ? ? ? ? ? y=int.Parse(result[i,1]);
? ? ? ? ? ? ? ? if (y > x)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? x = y;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? for (int j = 0; j < result.GetLongLength(0); j++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? y = int.Parse(result[j, 1]);
? ? ? ? ? ? ? ? if (x == y)
? ? ? ? ? ? ? ? {?
? ? ? ? ? ? ? ? ? ? string name=result[j,0];
? ? ? ? ? ? ? ? ? ? Console.WriteLine("分數(shù)最高的是"+name+",分數(shù)是:"+x);
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
2018-07-27
可以轉(zhuǎn)化再進行比較大小
例如string s=“123”;
int x=int.Parse(s);
2018-07-26
聲明scores 里面 int類型加了“ ”