using System;
using System.Collections.Generic;
using System.Text;
namespace projGetMaxScore
{
class Program
{
static void Main(string[] args)
{
string[] name=new string[8];
name[0]="吴松";
name[1]="钱东宇";
name[2]="伏晨";
name[3]="陈陆";
name[4]="周蕊";
name[5]="林日鹏";
name[6]="何昆";
name[7]="关欣";
int[] score=new int[] {89,90,98,56,60,91,93,85};
int max=score[0];
int count=0;
for(int i=1;i<8;i++ )
{
if(score[i]>max)
{
max=score[i];count=i;
}
}
Console.Write("分数最高的是"+name[count]+","
+"分数是"+score[count]);
}
}
}
第一个类初始值是string,要使用函数调用,分数是int类型,会出错
using System;
using System.Collections.Generic;
using System.Text;
namespace projGetMaxScore
{
class Program
{
static void Main(string[] args)
{
string[] name = { "吴宋", "钱东宇", "伏晨", "陈陆", "周蕊", "林日鹏", "何昆", "关欣" };
int[] fenshu = { 89, 90, 98, 56, 60, 91, 93, 85 };
int yy= Maxfenshu(fenshu);
Console.WriteLine("分数最高的是{0},分数是{1}", name[2], yy);
}
private static int Maxfenshu(int[] yy)
{
int max = yy[0];
for(int i=0;i<yy.Length;i++)
{
if (yy[i] > max)
max = yy[i];
}
return max;
}
}
通过了,是因为Console.Write("分数最高的是"+name[count]+"," +"分数是"+score[count]);里输出的逗号应该是中文的,不是英文符号