C# 如何将数组从高到低排序,并允许用户输入数组的一部分,而不是全部?

C# 如何将数组从高到低排序,并允许用户输入数组的一部分,而不是全部?,c#,arrays,C#,Arrays,我需要将数组从高到低排序,同时将它们的名称保留在分数旁边。另外,我如何允许用户只输入数组的一部分,而不是全部分配的10个空格 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace proj09LEA { class Program { const int SIZE =

我需要将数组从高到低排序,同时将它们的名称保留在分数旁边。另外,我如何允许用户只输入数组的一部分,而不是全部分配的10个空格

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace proj09LEA
{
    class Program
    {
        const int SIZE = 10;

        static void Main(string[] args)
        {
            // declare and array of integers          
            string[] name = new string[SIZE];
            int[] score = new int[SIZE];

            Console.WriteLine("\nSaturday Coder's Bowling Team");
            Console.WriteLine("Enter in a name and score for each person on the team.");
            Console.WriteLine("For example, Mary 143. Just hit Enter when you are done.\n");

            // fill an array with user input
            for (int i = 0; i < score.Length; i++)
            {
                Console.WriteLine("Enter in a name and score: ");
                string line = Console.ReadLine();

                name[i] = line.Substring(0, line.IndexOf(' '));
                score[i] = int.Parse(line.Substring(line.IndexOf(' ') + 1));
            }

            Console.WriteLine("------------ Input Complete ------------\n");
            Console.WriteLine("Here are the scores for this game:\n");

            for (int i = 0; i < score.Length; i++)
            {
                Console.WriteLine("{0}'s score was {1}.", name[i], score[i]);
            }

            Console.WriteLine();
            AverageScore(score);

            Console.WriteLine("Press Enter to continue. . .");
            Console.ReadLine();
        }

        static void AverageScore(int[] score)
        {
            int sum = score.Sum();
            int average = sum / score.Length;
            Console.WriteLine("The average score for this game was {0:d}.", average);
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
名称空间proj09LEA
{
班级计划
{
常数int SIZE=10;
静态void Main(字符串[]参数)
{
//整数的声明和数组
字符串[]名称=新字符串[大小];
整数[]分数=新整数[大小];
Console.WriteLine(\n星期四编码员的保龄球队);
Console.WriteLine(“输入团队中每个人的姓名和分数”);
WriteLine(“例如,Mary 143。完成后只需按Enter键。\n”);
//用用户输入填充数组
for(int i=0;i
试试这个:

Dictionary<string, int> playerScoreList = new Dictionary<string, int>();
playerScoreList.Add(name, score); // add user to dictionary
playerScoreList.OrderByDescending(s => s.Value); // sort by score descending
Dictionary playerScoreList=new Dictionary();
玩家核心列表。添加(姓名、分数);//将用户添加到字典
playerCoreList.OrderByDescending(s=>s.Value);//按分数递减排序

使用while循环,并在用户输入一个表示输入完成的值时终止。我在您的帖子中没有看到任何与您的问题相关的代码。您应该阅读并更改存储数据的方式。不是两个并行集合,而是创建一个类,并具有该类实例的一个数组。