Вот кое-что, что, мы надеемся, так или иначе поможет решить проблему.
У вас есть две игры / соревнования, давайте создадим для них enum
:
//...
public enum Competitions { Running, Swimming }
//...
Класс Attempt
, макс. два экземпляра этого объекта для каждого Athlete
независимо от типов соревнований.
//...
public class Attempt
{
public Competitions Competition { get; set; }
public int Score { get; set; }
}
//...
Класс Athlete
:
//...
public class Athlete
{
public string Name { get; set; }
public readonly List<Attempt> Attempts = new List<Attempt>();
public override string ToString() => Name;
}
//...
И еще один класс, который будет отчетом / запись статистики / статуса (назовите ее) для каждого спортсмена.
//...
public class Statistics
{
public string Name { get; set; }
public int Running { get; set; }
public int Swimming { get; set; }
public int TotalScore { get => Running + Swimming; }
public int RunningRank { get; set; }
public int SwimmingRank { get; set; }
public int GeneralRank { get; set; }
}
//...
В вашей реализации у вас есть List<Athlete>
, заполненный некоторыми записями, например:
//...
List<Athlete> Athletes = new List<Athlete>();
private void CreateList()
{
Athletes.Clear();
var jim = new Athlete { Name = "Jim" };
jim.Attempts.Add(new Attempt { Competition = Competitions.Swimming, Score = 1 });
jim.Attempts.Add(new Attempt { Competition = Competitions.Swimming, Score = 2 });
var joe = new Athlete { Name = "Joe" };
joe.Attempts.Add(new Attempt { Competition = Competitions.Running, Score = 7 });
joe.Attempts.Add(new Attempt { Competition = Competitions.Swimming, Score = 2 });
var sue = new Athlete { Name = "Sue" };
sue.Attempts.Add(new Attempt { Competition = Competitions.Running, Score = 3 });
sue.Attempts.Add(new Attempt { Competition = Competitions.Swimming, Score = 7 });
var bob = new Athlete { Name = "Bob" };
bob.Attempts.Add(new Attempt { Competition = Competitions.Running, Score = 10 });
bob.Attempts.Add(new Attempt { Competition = Competitions.Swimming, Score = 10 });
var ben = new Athlete { Name = "Ben" };
ben.Attempts.Add(new Attempt { Competition = Competitions.Running, Score = 5 });
var sam = new Athlete { Name = "Sam" };
sam.Attempts.Add(new Attempt { Competition = Competitions.Running, Score = 6 });
sam.Attempts.Add(new Attempt { Competition = Competitions.Running, Score = 4 });
Athletes.AddRange(new[] { jim, joe, sue, bob, ben, sam });
}
//...
Сейчас давайте создадим статистику или отчет для каждого члена , где сумма их попыток бега и плавания равна.
//...
private IEnumerable<Statistics> CreateStatistics()
{
var ath = Athletes.Where(x => x.Attempts.Count() == 2
&& x.Attempts.First().Competition != x.Attempts.Last().Competition);
var abi = (from a in ath
select new Statistics
{
Name = a.Name,
Running = a.Attempts
.First(r => r.Competition == Competitions.Running).Score,
Swimming = a.Attempts
.First(s => s.Competition == Competitions.Swimming).Score,
}).ToList();
foreach (var a in abi)
{
a.RunningRank = 1 + abi.Select(r => r.Running).OrderByDescending(r => r)
.ToList().IndexOf(a.Running);
a.SwimmingRank = 1 + abi.Select(s => s.Swimming).OrderByDescending(s => s)
.ToList().IndexOf(a.Swimming);
a.GeneralRank = 1 + abi.Select(t => t.TotalScore).OrderByDescending(t => t)
.ToList().IndexOf(a.TotalScore);
}
return abi;
}
//...
Результат:

Как вы можете видеть, запрос выбрал только трех участников из списка и создал запись статистики для каждого, которая показывает их очки и вычисляет их ранги для каждой игры, а также общее или общее звание.
Удачи.