慕粉2003103133
2018-07-17 09:54
using System;
using System.Collections.Generic;
using System.Text;
namespace projGetMaxScore
{
class Program
{
static void Main(string[] args)
{
object [,] names = new object[8, 2]{
{"吴松",89},{"钱东宇",90},{"伏晨",98},{"陈陆",56},{"周蕊",60},{"林日鹏",91},{"何昆",93},{"关欣",85}
};
object temp = 0;
object maxscore = 0;
object name = null;
for (int i = 0; i < names.GetLongLength(0); i++)
{
temp = names[i, 1];
if ((int)maxscore < (int)temp)
{
maxscore = temp;
name = (string)names[i, 0];
}
else
{
continue;
}
}
Console.Write("分数最高的是" + name + ",分数是" + maxscore+",");
}
}
}
string [] name = new string [] { "吴松","钱东宇","伏晨","陈陆","周蕊","林日鹏","何昆","关欣" };
int [] branch = new int [] { 89,90,98,56,60,91,93,85};
int zuigao = 0;
int index = 0;
for(int i=0;i<branch.Length;i++){
if(zuigao>branch[i] == false){
zuigao = branch[i];
index = i;
}
}
Console.Write("分数最高的是{0},分数是{1}",name[index],branch[index]);
string [] name = new string [] { "吴松","钱东宇","伏晨","陈陆","周蕊","林日鹏","何昆","关欣" };
int [] score = new int [] { 89,90,98,56,60,91,93,85};
int high = 0;
int index = 0;
for(int i=0;i<score.Length;i++)
{
if(high<score[i])
{
high = score[i];
index = i;
}
}
Console.WriteLine("分数最高的是{0},分数是{1}",name[index],score[index]);
string [,] test = new string[8,2]{{"吴松","89"},{"钱东宇","90"},{"伏晨","98"},{"陈陆","56"},{"周蕊","60"},{"林日鹏","91"},{"何昆","93"},{"关欣","85"}};
int max = 0;
int index=0;
for (int i=0;i<test.GetLongLength(0);i++)
{
if (max<int.Parse(test[i,1]))
{
max=int.Parse(test[i,1]);
index=i;
}
}
Console.Write("分数最高的是{0},分数是{1}",test[index,0],max);
我把object的声明改了。使用了两种做法。
using System;
using System.Collections.Generic;
using System.Text;
namespace projGetMaxScore
{
class Program
{
static void Main(string[] args)
{
//第一种方法
string [,] names = new string[8, 2]{
{"吴松","89"},{"钱东宇","90"},{"伏晨","98"},{"陈陆","56"},{"周蕊","60"},{"林日鹏","91"},{"何昆","93"},{"关欣","85"}
};
int temp = 0;
int maxscore = 0;
string name = null;
for (int i = 0; i < names.GetLongLength(0); i++)
{
temp = int.Parse(names[i, 1]);
if (maxscore < temp)
{
maxscore = temp;
name = names[i, 0];
}
else
{
continue;
}
}
Console.Write("分数最高的是" + name + ",分数是" + maxscore+",");
//第二种方法索引法。
string[,] info = new string[8, 2] { { "吴松", "89" }, { "钱东宇", "90" }, { "伏晨", "98" }, { "陈陆", "56" }, { "周蕊", "60" }, { "林日鹏", "9" }, { "何昆", "93" }, { "关欣", "85" } };
int temp2 = 0;
for (int i = 0; i < info.GetLongLength(0); i++)
{
if (int.Parse(info[i, 1]) > int.Parse(info[temp2, 1]))
{
temp2 = i;
}
}
Console.Write("分数最高的是" + info[temp2, 0] + ",分数是" + info[temp2, 1]);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace projGetMaxScore
{
class Program
{
static void Main(string[] args)
{
string[]names={"吴松","钱东宇","伏晨","陈陆","周蕊","林日鹏","何昆","关欣"};
int[]score={89,90,98,56,60,91,93,85};
int MAX=score[0];
string maxName=names[0];
for(int i=0;i<score.Length;i++)
{
if(score[i]>MAX)
{
MAX=score[i];
maxName=names[i];
}
}
Console.Write("分数最高的是{0},分数是{1}",maxName,MAX);
}
}
}
请问为什么要用object?
好好好
C#开发轻松入门
254118 学习 · 1459 问题
相似问题