C# 排序字符串和整数。高整数在顶部,字符串的顺序相同
我有一些团队:C# 排序字符串和整数。高整数在顶部,字符串的顺序相同,c#,arrays,C#,Arrays,我有一些团队: int[] numbers = new int[4]; string[] Teams = {"Team1", "Team2", "Team3","Team4"}; 他们都以0分开始 Team1 0 Team2 0 Team3 3 Team4 0 如果一个队赢了,得到3个b.v:(第1队对第3队)第3队赢了比赛。他爬到了山顶。然后球队赢了 Team3 3 Team1 0 Te
int[] numbers = new int[4];
string[] Teams = {"Team1", "Team2", "Team3","Team4"};
他们都以0分开始
Team1 0
Team2 0
Team3 3
Team4 0
如果一个队赢了,得到3个b.v:(第1队对第3队)第3队赢了比赛。他爬到了山顶。然后球队赢了
Team3 3
Team1 0
Team2 0
Team4 0
我找不到一种方法来获取字符串数组,其中最高的int数组位于顶部。按礼节顺序。
它必须与ARRAY一起使用。您应该有一个类似于以下的类团队
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;}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
公共课程
{
公共静态void Main()
{
var list=新列表();
添加(新团队{Score=1,TeamName=“Test”});
添加(新团队{Score=1,TeamName=“Test 2”});
添加(新团队{Score=1,TeamName=“Test 3”});
添加(新团队{Score=4,TeamName=“test4”});
添加(新团队{Score=1,TeamName=“Test 5”});
var ordered=list.OrderByDescending(l=>l.Score);
ordered.Dump();
}
公开课小组
{
公共整数分数{get;set;}
公共字符串TeamName{get;set;}
}
}
这应该不会太难。你需要找到得分最高的团队的索引,然后对两个数组进行排序。你能分享你的方法吗?不过,不确定将分数存储在
团队
类中是否有意义,是吗?得分通常是针对一场特定的比赛(或可能是一个系列赛),而团队
可能会出现很多赛季。