Advertisement
miljdze

Untitled

Dec 15th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. namespace ConsoleApplication180
  7. {
  8. class Program
  9. {
  10. struct Korisnik
  11. {
  12. public string ime;
  13. public string prezime;
  14. public ushort ID;
  15.  
  16. }
  17. static void Main(string[] args)
  18. {
  19.  
  20. List<Korisnik> ListaKorisnika = new List<Korisnik>();
  21. Korisnik korisnik;
  22. string opcija = "";
  23. string lokacija = "Korisnici.txt";
  24. int brojKorisnika = ListaKorisnika.Count;
  25. if (File.Exists(lokacija))
  26. {
  27. StreamReader f = File.OpenText(lokacija);
  28. brojKorisnika = int.Parse(f.ReadLine());
  29. f.ReadLine();
  30. foreach (var kor in ListaKorisnika)
  31. {
  32. korisnik.ime = f.ReadLine();
  33. korisnik.prezime = f.ReadLine();
  34. korisnik.ID = ushort.Parse(f.ReadLine());
  35. f.ReadLine();
  36. }
  37. f.Close();
  38. }
  39.  
  40. do {
  41. Console.WriteLine("Unesite ime: ");
  42. korisnik.ime = Console.ReadLine();
  43. opcija = korisnik.ime;
  44. if (opcija == "end")
  45. break;
  46. Console.WriteLine("Unesite prezime: ");
  47. korisnik.prezime = Console.ReadLine();
  48. opcija = korisnik.prezime;
  49. if (opcija == "end")
  50. break;
  51. Console.WriteLine("Unesite ID: ");
  52. korisnik.ID = ushort.Parse(Console.ReadLine());
  53. ListaKorisnika.Add(korisnik);
  54.  
  55. } while (opcija != "end");
  56.  
  57. StreamWriter w = File.CreateText(lokacija);
  58. int brKor = ListaKorisnika.Count;
  59. w.WriteLine(brKor);
  60. w.WriteLine();
  61. foreach (var kor in ListaKorisnika)
  62. {
  63. w.WriteLine(kor.ime);
  64. w.WriteLine(kor.prezime);
  65. w.WriteLine(kor.ID);
  66. w.WriteLine();
  67. }
  68. w.Close();
  69. Console.ReadKey();
  70.  
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement