Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp5
- {
- class Program
- {
- static List<Osoba> osoby = new List<Osoba>();
- static void Main(string[] args)
- {
- Osoba.dodaj();
- Osoba.wypisz();
- Console.ReadKey();
- }
- class Osoba
- {
- public string Imie;
- public string Nazwisko;
- public int wiek;
- Osoba()
- {
- Imie = Console.ReadLine();
- Nazwisko = Console.ReadLine();
- while(!int.TryParse(Console.ReadLine(), out wiek))
- {
- Console.WriteLine("Nie podales liczby");
- }
- }
- public static void dodaj()
- {
- int liczba;
- Console.WriteLine("Ile osob chcesz dodac do listy ? : ");
- while (!int.TryParse(Console.ReadLine(), out liczba))
- {
- Console.WriteLine("Nie podales liczby");
- }
- for (int i = 0; i < liczba; i++)
- {
- Osoba gosciu = new Osoba();
- osoby.Add(gosciu);
- }
- }
- public static void wypisz()
- {
- Console.WriteLine("================");
- Console.WriteLine("Lista osob:");
- foreach (Osoba osoba in osoby)
- {
- string imie = osoba.Imie;
- string nazwisko = osoba.Nazwisko;
- int wiek = osoba.wiek;
- Console.WriteLine($"{wiek} {imie} {nazwisko}");
- }
- Console.WriteLine("================");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement