Нужно подсчитать сколько учеников в 9 классе больше чем в 10, или НАОБОРОТ

Вот задача: Вывести на экран сведения об учениках только десятых классов. <--сделал

На сколько человек в девятых классах больше, чем в десятых. <--нужна помощь

using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp2
{
public struct Shcoll
{
    private int Id { get; set; }
    private int Clas { get; set; }
    private int Uspev { get; set; }

    public Shcoll(int id, int clas, int uspev)
    {
        Id = id;
        Clas = clas;
        Uspev = uspev;
    }

    public static Shcoll Uchinik(int i)
    {
        Random rand = new Random();
        int id = i;
        int clas = rand.Next(9,11);
        int uspev = rand.Next(2,5);

        return new Shcoll(id,clas,uspev);
    }

    public void srav()
    {
        if (clas == 10)
        {
            Console.WriteLine("id ученика - |{0}|, успеваемость - |{1}|",id, uspev);
        }
    }
}

class Program
{
    public static void Main()
    {
        List<Shcoll> uchenik = new List<Shcoll>();
        for (int i = 0; i < 25; i++)
        {
            Shcoll m = Shcoll.Uchinik(i + 1);
            uchenik.Add(m);
        }
        Console.WriteLine("Данные 10-ых классов:");
        foreach (Shcoll p in uchenik)
        {
            p.srav();
        }
    }

}

}


Ответы (1 шт):

Автор решения: Kaminoyti
int cl9 = 0;
int cl10 = 0;
int ColVo = 0;
for(int i=0;i<25;i++)
{
 if (uchenik[i].Clas == 10)
    cl10++;
 if (uchenik[i].Clas == 9)
    cl9++;
}
if (cl9 > cl10)
{
 ColVo = cl9 - cl10;
 Console.WriteLine("Учеников в 9-ом классе больше, чем в 10-ом на: "+ ColVo);
}
else
{
 ColVo = cl10 - cl9;
 Console.WriteLine("Учеников в 10 классе больше, чем в 9-ом на: "+ ColVo);
}

Добавить этот код в public static void Main()

И полю Clas, в классе Shcoll. Дать public

→ Ссылка