Skip to content

Commit

Permalink
Linq - knihy final
Browse files Browse the repository at this point in the history
  • Loading branch information
moravcikj24 authored and moravcikj24 committed Nov 19, 2024
1 parent 4a7488f commit 80747f7
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 11 deletions.
39 changes: 33 additions & 6 deletions LINQ - kniha/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.ExceptionServices;

namespace LINQ___kniha
{
Expand All @@ -12,17 +14,42 @@ public static void Main(string[] args)
new Kniha { Autor = "Anna Hruskova",RokVydania = 2009, JePreDeti = false },
new Kniha { Autor = "Bob", RokVydania = 2022, JePreDeti = true },
new Kniha { Autor = "Charlie", RokVydania = 2018, JePreDeti = true },
new Kniha { Autor = "Bob", RokVydania = 2020 , JePreDeti = false},
new Kniha { Autor = "Imrich", RokVydania = 2020 , JePreDeti = false},
new Kniha { Autor = "Imrich 2", RokVydania = 2020 , JePreDeti = false},
new Kniha { Autor = "Imrich 3", RokVydania = 2020 , JePreDeti = false},
};


List<Kniha> knihaJePreDeti = Knihy.Where(kniha => kniha.JePreDeti == true).ToList();
foreach (Kniha kniha in knihaJePreDeti)
List<Kniha> knihyOdNajstarsej = Knihy.OrderBy(kniha => kniha.RokVydania).ToList();
List<Kniha> kinhyOdNajmladsej = Knihy.OrderByDescending(kniha => kniha.RokVydania).ToList();
List<Kniha> knihyPreDetiOdNajstarsej = Knihy.Where(kniha => kniha.JePreDeti).OrderBy(kniha => kniha.RokVydania).ToList(); //!kniha = negacia cize False = True a naopak

var knihyPodlaRoku = Knihy.GroupBy(u => u.RokVydania).Select(grp => grp.ToList()).ToList();

Kniha Prvaknizaold = Knihy[0];
Kniha prvakniha = Knihy.Last();

foreach (List<Kniha> skupinka in knihyPodlaRoku)
{
Console.WriteLine($"Skupinka:");

foreach (Kniha kniha in skupinka)
{
Console.WriteLine($" Autor: {kniha.Autor},{kniha.RokVydania}, {kniha.JePreDeti} je pre deti ");
}

}
Console.WriteLine();
var knihyPodlaRoku_IDictionary = Knihy.GroupBy(o => o.RokVydania).ToDictionary(g => g.Key, g => g.ToList());
foreach (var skupinka in knihyPodlaRoku_IDictionary)
{
Console.WriteLine($" Autor: {kniha.Autor}, {kniha.RokVydania}. Je pre deti ? { kniha.JePreDeti}");
Console.WriteLine($"Skupinka {skupinka.Key}");
foreach (Kniha kniha in skupinka.Value)
{
Console.WriteLine($" Autor: {kniha.Autor},{kniha.RokVydania}, {kniha.JePreDeti} je pre deti ");
}
}
}


}
}
16 changes: 13 additions & 3 deletions LINQ/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,29 @@ static void Main(string[] args)
new Student { Name = "Charlie", Age = 18 }
};

/* List<Student> tinedzeriStudenti_stary = new List<Student>();

//Prehladavanie list, ziskali sme vsetkych studentov s menom Anna
List<Student> tinedzeriStudenti_stary = new List<Student>();
foreach(Student student in students)
{
if (student.Age < 20)
if (student.Name.Contains("Anna"))
{
tinedzeriStudenti_stary.Add(student);
}
}
/*
List<Student> tinedzeristudenti = students.Where(student => student.Age < 20).ToList();
foreach (Student student in tinedzeriStudenti_stary)
{
Console.WriteLine($"Stary sposob: Student {student.Name} ma {student.Age} a je tinedzer");
}
List<Student> tinedzeriStudenti_stary = new List<Student>();
foreach(Student student in students)
{
if (student.Age < 20)
{
tinedzeriStudenti_stary.Add(student);
}
}*/


Expand Down
4 changes: 4 additions & 0 deletions src/AppsLab-033-NuGet/AppsLab-033-NuGet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
19 changes: 17 additions & 2 deletions src/AppsLab-033-NuGet/Program.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
using Newtonsoft.Json;
using System;

namespace AppsLab_033_NuGet
{
class Program
{
static void Main(string[] args)
{
var person = new { Name = "Jano", Age = 25 };

string json = JsonConvert.SerializeObject(person, Formatting.Indented);

Console.WriteLine(json);
}
}
}

0 comments on commit 80747f7

Please sign in to comment.