为了账号安全,请及时绑定邮箱和手机立即绑定

有没有更简单的代码

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+",");
        }
    }
}

正在回答

7 回答

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]);


3 回复 有任何疑惑可以回复我~

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]);


1 回复 有任何疑惑可以回复我~

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);


0 回复 有任何疑惑可以回复我~

我把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]);
        }
    }
}

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);

        }

    }

}


1 回复 有任何疑惑可以回复我~

请问为什么要用object?

0 回复 有任何疑惑可以回复我~
#1

qq_初五_3

一般不用object, 这个object是所有类型的基类,包含所有数据类型。
2018-07-25 回复 有任何疑惑可以回复我~
#2

慕粉2003103133 提问者 回复 qq_初五_3

object已经改掉了
2018-07-31 回复 有任何疑惑可以回复我~

好好好

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
C#开发轻松入门
  • 参与学习       254034    人
  • 解答问题       1459    个

本门课程是C#语言的入门教程,将带你轻松入门.NET开发

进入课程

有没有更简单的代码

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信