Cassimus

linq

Aug 30th, 2025
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. // List<int> liczby = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  2.  
  3. // foreach (int liczba in liczby)
  4. // {
  5. // if (liczba % 2 == 0)
  6. // {
  7. // System.Console.WriteLine(liczba);
  8. // }
  9. // }
  10.  
  11. // var parzyste = liczby.Where(x => x % 2 == 0).ToList();
  12.  
  13. // foreach (var n in parzyste)
  14. // {
  15. // System.Console.WriteLine(n);
  16. // }
  17.  
  18. // List<string> imiona = new List<string> { "Wojtek", "Hania", "Szymon", "Zosia" };
  19. // var posortowane = imiona.OrderByDescending(imie => imie).ToList();
  20.  
  21. // foreach (var imie in posortowane)
  22. // {
  23. // System.Console.WriteLine(imie);
  24. // }
  25.  
  26. // var min = liczby.Min();
  27. // System.Console.WriteLine(min);
  28.  
  29. // System.Console.WriteLine(liczby.Max());
  30.  
  31. // System.Console.WriteLine(liczby.Sum());
  32. // System.Console.WriteLine(liczby.Average());
  33.  
  34. // Utwórz listę studentów. Lista ma zawierać 4 studentów.
  35. // Każdy student ma imie, wiek i średnią ocen.
  36. // Student jest osobnym obiektem.
  37. // Używając LINQ (wyrażenia Where) filtruj listę studentów do tych,
  38. // którzy mają więcej niż 20 lat. Pamiętajmy, żeby dodać klasę
  39. // Student oraz klasę programu z metodą Main.
  40.  
  41. public class Student
  42. {
  43. public string Imie { get; set; }
  44. public int Wiek { get; set; }
  45. public float Srednia { get; set; }
  46. }
  47.  
  48.  
Advertisement
Add Comment
Please, Sign In to add comment