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"},{"关欣","85"}}
for(int i=0;i<8;i++)
{
if((int)score[i,1]>max)
{
max=(int)score[i,1];
}
}
Console.WriteLine("最高分的是"+score[max,0]+"分数是"+score[max,1]);
}
}
}
不能强制转换string为int,你可以使用string.compare比较,Convert.toInt32转换,int.Parse()转换等
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" }, { "关欣", "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] + "分数是" + score[max, 1]);
}
}
}
最大值,与最大值的下标是两个值,需要两个变量来单独存放。