這樣有什么問題?
using System;
using System.Collections.Generic;
using System.Text;
namespace projGetMaxScore
{
??? class Program
??? {
??????? static void Main(string[] args)
??????? {
??????????? int max=0;
??????????? string [,]score={{"吳松","89"},{"錢東宇","90"},{"伏晨","98"},{"陳陸","56"},{"周蕊","60"},{"林日鵬","91"},{"何昆","93"},{"關(guān)欣","85"}}
??????????? for(int i=0;i<8;i++)
??????????? {
??????????????? if((int)score[i,1]>max)
??????????????? {
??????????????????? max=(int)score[i,1];
??????????????? }
??????????? }
??????????? Console.WriteLine("最高分的是"+score[max,0]+"分數(shù)是"+score[max,1]);
??????? }
??? }
}
2018-04-24
不能強制轉(zhuǎn)換string為int,你可以使用string.compare比較,Convert.toInt32轉(zhuǎn)換,int.Parse()轉(zhuǎn)換等
2017-07-16
using System;
using System.Collections.Generic;
using System.Text;
namespace projGetMaxScore
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? int max = 0;
? ? ? ? ? ? string[,] score = { { "吳松", "89" }, { "錢東宇", "90" }, { "伏晨", "98" }, { "陳陸", "56" }, { "周蕊", "60" }, { "林日鵬", "91" }, { "何昆", "93" }, { "關(guān)欣", "85" } };
? ? ? ? ? ? int fen = int.Parse(score[0, 1]);
? ? ? ? ? ? for (int i = 0; i < 8; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (int.Parse(score[i, 1]) > fen)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? fen = int.Parse(score[i, 1]);
? ? ? ? ? ? ? ? ? ? max = i;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? Console.WriteLine("最高分的是" + score[max, 0] + "分數(shù)是" + score[max, 1]);
? ? ? ? }
? ? }
}
最大值,與最大值的下標是兩個值,需要兩個變量來單獨存放。