+ Нов въпрос

Здравейте колеги, имам бъг и не успявам да се справя. Задачата е 6 от Associative Arrays Exercise , моля за съдействие. Благодаря предварително!

Тагове:
0
Axiomatik 2422 Точки

No sorting required for this exercise, just print out the data as received =>

;-)

``````using System;
using System.Collections.Generic;
using System.Linq;
namespace _06.Courses
{
class Program
{
static void Main(string[] args)
{
Dictionary<string, List<string>> studentByCourse = new Dictionary<string, List<string>>();
while (true)
{
if (line == "end")
{
break;
}
string[] parts = line.Split(" : ", StringSplitOptions.RemoveEmptyEntries)
.ToArray();

string course = parts[0];
string student = parts[1];

if (!studentByCourse.ContainsKey(course))
{
}
else
{
}
}
// foreach (var course in studentByCourse.OrderByDescending(x => x.Value.Count()))
foreach (var course in studentByCourse)
{
Console.WriteLine(\$"{course.Key}: {course.Value.Count()}");
//    foreach (var name in course.Value.OrderBy(x =>x))
foreach (var name in course.Value)
{
Console.WriteLine(\$"-- {name}");
}
}
// Dictionary<string, List<string>> sortedCourse = studentByCourse
//     .OrderByDescending(c => c.Value.Count)
//     .ToDictionary(x => x.Key, x => x.Value);

// foreach (var kvp in sortedCourse)
// {
//     Console.WriteLine(\$"{kvp.Key}: {kvp.Value.Count}");
//     List<string> sortedStudents = kvp.Value
//         .OrderByDescending(x => x)
//         .ToList();
//     //course.Value.Sort();
//     foreach (var student in sortedStudents)
//     {
//         Console.WriteLine(\$"-- {student}");
//     }
// }
}
}
}
``````

1