Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp5
  8. {
  9. class Program
  10. {
  11. static List<Osoba> osoby = new List<Osoba>();
  12. static void Main(string[] args)
  13. {
  14. Osoba.dodaj();
  15. Osoba.wypisz();
  16. Console.ReadKey();
  17. }
  18. class Osoba
  19. {
  20. public string Imie;
  21. public string Nazwisko;
  22. public int wiek;
  23. Osoba()
  24. {
  25. Imie = Console.ReadLine();
  26. Nazwisko = Console.ReadLine();
  27. while(!int.TryParse(Console.ReadLine(), out wiek))
  28. {
  29. Console.WriteLine("Nie podales liczby");
  30. }
  31. }
  32. public static void dodaj()
  33. {
  34. int liczba;
  35. Console.WriteLine("Ile osob chcesz dodac do listy ? : ");
  36. while (!int.TryParse(Console.ReadLine(), out liczba))
  37. {
  38. Console.WriteLine("Nie podales liczby");
  39. }
  40. for (int i = 0; i < liczba; i++)
  41. {
  42. Osoba gosciu = new Osoba();
  43. osoby.Add(gosciu);
  44. }
  45.  
  46. }
  47. public static void wypisz()
  48. {
  49. Console.WriteLine("================");
  50. Console.WriteLine("Lista osob:");
  51. foreach (Osoba osoba in osoby)
  52. {
  53. string imie = osoba.Imie;
  54. string nazwisko = osoba.Nazwisko;
  55. int wiek = osoba.wiek;
  56. Console.WriteLine($"{wiek} {imie} {nazwisko}");
  57. }
  58. Console.WriteLine("================");
  59. }
  60.  
  61. }
  62.  
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement