-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
62 lines (51 loc) · 1.48 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LinqNakupSeznam
{
class Program
{
static void Main(string[] args)
{
string[] categories = { "ovoce a zelenina", "luštěniny", "pečivo", "mléčné výrobky", "maso", "sladkosti", "nápoje", "ostatní" };
List<Item> items = new List<Item>();
Item def = new Item("-");
for (int i = 0; i < categories.Length; i++)
{
Console.WriteLine($"[{i}]: {categories[i]}");
}
Console.WriteLine("-------------------------------------");
bool nextItem = true;
while (nextItem)
{
Console.Write("Položka: ");
string name = Console.ReadLine();
Console.Write("Kategorie: ");
int category = int.Parse(Console.ReadLine());
Console.Write("Přidat další položku [ano/ne]: ");
string agreeNext = Console.ReadLine();
items.Add(new Item(name, categories[category]));
if (agreeNext == "ne")
{
nextItem = false;
Console.WriteLine("-------------------------------------");
}
}
var task = from j in categories
join u in items on j equals u.Category into ju
select new { Category = j , Items = ju.DefaultIfEmpty(def)};
foreach (var group in task)
{
Console.WriteLine();
Console.Write($" {(group.Category).ToUpper()}: ");
foreach (var u in group.Items)
{
Console.Write(u.Name);
}
Console.WriteLine();
}
}
}
}