Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- String path = @"C:\users\public\samochody.txt";
- Console.WriteLine("Ile samochodow dodac?: ");
- List<Samochod> listaSamochodow = new List<Samochod>();
- int wybor = 0;
- do
- {
- Console.WriteLine("MENU");
- Console.WriteLine("1. Dodaj auto:");
- Console.WriteLine("2. Wyświetl liste");
- Console.WriteLine("3. Wczytaj auta z pliku");
- Console.WriteLine("4. Zapisz liste do pliku");
- Console.WriteLine("5. Wyczysc liste");
- Console.WriteLine("6. Wyjdź");
- wybor = Int32.Parse(Console.ReadLine());
- switch(wybor)
- {
- case 1:
- {
- listaSamochodow.Add(new Samochod());
- break;
- }
- case 2:
- {
- foreach(Samochod autko in listaSamochodow)
- {
- autko.WyswietlInfo();
- }
- break;
- }
- case 3:
- {
- string[] lines = File.ReadAllLines(path, Encoding.UTF8);
- string[] dane = new string[3];
- int i = 0;
- foreach (string line in lines)
- {
- dane[i] = line;
- i++;
- if (i == 3)
- {
- i = 0;
- listaSamochodow.Add(new Samochod(dane[0], dane[1], int.Parse(dane[2])));
- }
- }
- break;
- }
- case 4:
- {
- foreach (Samochod s1 in listaSamochodow)
- {
- File.AppendAllText(path, s1.marka);
- File.AppendAllText(path, Environment.NewLine);
- File.AppendAllText(path, s1.model);
- File.AppendAllText(path, Environment.NewLine);
- File.AppendAllText(path, s1.predkosc.ToString());
- File.AppendAllText(path, Environment.NewLine);
- }
- break;
- }
- case 5:
- {
- listaSamochodow.Clear();
- break;
- }
- }
- } while (wybor != 6);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement