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.IO;
- namespace ConsoleApplication180
- {
- class Program
- {
- struct Korisnik
- {
- public string ime;
- public string prezime;
- public ushort ID;
- }
- static void Main(string[] args)
- {
- List<Korisnik> ListaKorisnika = new List<Korisnik>();
- Korisnik korisnik;
- string opcija = "";
- string lokacija = "Korisnici.txt";
- int brojKorisnika = ListaKorisnika.Count;
- if (File.Exists(lokacija))
- {
- StreamReader f = File.OpenText(lokacija);
- brojKorisnika = int.Parse(f.ReadLine());
- f.ReadLine();
- foreach (var kor in ListaKorisnika)
- {
- korisnik.ime = f.ReadLine();
- korisnik.prezime = f.ReadLine();
- korisnik.ID = ushort.Parse(f.ReadLine());
- f.ReadLine();
- }
- f.Close();
- }
- do {
- Console.WriteLine("Unesite ime: ");
- korisnik.ime = Console.ReadLine();
- opcija = korisnik.ime;
- if (opcija == "end")
- break;
- Console.WriteLine("Unesite prezime: ");
- korisnik.prezime = Console.ReadLine();
- opcija = korisnik.prezime;
- if (opcija == "end")
- break;
- Console.WriteLine("Unesite ID: ");
- korisnik.ID = ushort.Parse(Console.ReadLine());
- ListaKorisnika.Add(korisnik);
- } while (opcija != "end");
- StreamWriter w = File.CreateText(lokacija);
- int brKor = ListaKorisnika.Count;
- w.WriteLine(brKor);
- w.WriteLine();
- foreach (var kor in ListaKorisnika)
- {
- w.WriteLine(kor.ime);
- w.WriteLine(kor.prezime);
- w.WriteLine(kor.ID);
- w.WriteLine();
- }
- w.Close();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement