首页 > 解决方案 > 订购一个字符串和整数。高 int 在顶部,字符串遵循相同的顺序

问题描述

我有一些团队:

int[] numbers = new int[4];
string[] Teams = {"Team1", "Team2", "Team3","Team4"};

他们都以0分开始

Team1   0
Team2   0
Team3   3
Team4   0

如果一支球队获胜,则获得 3 bv:(Team1 vs Team3)Team3 赢得了比赛。他到达了边界的顶端。然后团队获胜...

Team3   3
Team1   0
Team2   0
Team4   0

我找不到一种方法来获取顶部具有最高int 数组的字符串数组。以第 ri 顺序。 它必须与阵列。

标签: c#arrays

解决方案


您应该有一个类似于以下的类Team 。

using System;
using System.Collections.Generic;
using System.Linq;
                    
public class Program
{
    public static void Main()
    {
        var list = new List<Team>();
        list.Add(new Team{ Score = 1, TeamName = "Test"});
        list.Add(new Team{ Score = 1, TeamName = "Test 2"});
        list.Add(new Team{ Score = 1, TeamName = "Test 3"});
        list.Add(new Team{ Score = 4, TeamName = "Test 4"});
        list.Add(new Team{ Score = 1, TeamName = "Test 5"});
        
        var ordered = list.OrderByDescending(l => l.Score);
        ordered.Dump();
    }
    
    public class Team
    {
        public int Score {get;set;}
        public string TeamName {get;set;}
    }
}

https://dotnetfiddle.net/


推荐阅读