Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 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. using System.IO;
  7.  
  8. namespace ConsoleApp1
  9. {
  10. class Program
  11. {
  12. struct nevek
  13. {
  14. public string nev;
  15. public int evszam;
  16. }
  17. static List<nevek> lista = new List<nevek>();
  18. static void Main(string[] args)
  19. {
  20. nevek temp;
  21. StreamReader f = new StreamReader("nevek.txt");
  22. while (!f.EndOfStream)
  23. {
  24. string[] darabolt = f.ReadLine().Split(';');
  25. temp.nev = darabolt[0];
  26. temp.evszam = int.Parse(darabolt[1]);
  27. lista.Add(temp);
  28. }
  29. for (int i = 0; i < lista.Count; i++)
  30. {
  31. for (int j = 1; j < lista.Count; j++)
  32. {
  33. if (lista[j].evszam < lista[j-1].evszam)
  34. {
  35. temp = lista[j];
  36. lista[j] = lista[j-1];
  37. lista[j-1] = temp;
  38. }
  39. }
  40. }
  41. StreamWriter g = new StreamWriter("nevek2.txt");
  42. foreach (var item in lista)
  43. {
  44. Console.WriteLine(item.nev + " - " + item.evszam);
  45. g.WriteLine(item.nev + " - " + item.evszam);
  46. }
  47. g.Close();
  48. Console.ReadKey();
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement