语法没有问题,但是只能打印出平均分和“景珍”这个名字
string[,] score = new string[,] { {"景珍","90"}, {"林惠洋", "65" }, {"洪南昌","70" }, { "龙玉民", "46" },
{ "单江开", "81" }, { "田武山", "100" }, { "王三明", "68" }};
float sum = 0;
float avg = 0;
for ( int i = 0;i < score.GetLongLength(1);i++ )
{
sum += Convert.ToInt64(score[i, 1]);
}
avg = sum / score.GetLongLength(1);
Console.WriteLine("平均分是{0}", avg);
for (int i = 0; i < score.GetLongLength(1); i++)
{
if (avg< float.Parse(score[i, 1]))
{
Console.WriteLine("高于平均分的有:"+score[i,0]);
}
}
原来是维度选错了,应该是 score.GetLongLength(0),获取第一维度的长度