Advertisement
Guest User

Untitled

a guest
May 3rd, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Xml;
  9. using System.Xml.Serialization;
  10.  
  11. namespace zad3
  12. {
  13.     public partial class WebForm1 : System.Web.UI.Page
  14.     {
  15.         public class osoba : IComparer<osoba> //: IEqualityComparer<osoba>
  16.         {
  17.             public int Id;
  18.             public string Imie;
  19.             public string Nazwisko;
  20.             public int wiek;
  21.  
  22.         /*    public bool Equals(osoba a1, osoba a2)
  23.             {
  24.                 if (a1.Id == a2.Id && a1.Imie == a2.Imie && a1.Nazwisko == a2.Nazwisko && a1.wiek == a2.wiek)
  25.                     return true;
  26.                 else
  27.                     return false;
  28.             }
  29.             public int GetHashCode(osoba oso)
  30.             {
  31.                 return 0;
  32.             }*/
  33.             public int Compare(osoba a1, osoba a2)
  34.             {
  35.                 if (a1.Id == a2.Id && a1.Imie == a2.Imie && a1.Nazwisko == a2.Nazwisko && a1.wiek == a2.wiek)
  36.                     return 0;
  37.                 if (a1.wiek < a2.wiek)
  38.                     return -1;
  39.                 else
  40.                     return 1;
  41.             }
  42.  
  43.         }
  44.  
  45.    
  46.  
  47.         protected void Page_Init(object sender, EventArgs e)
  48.         {
  49.             List<osoba> lista = new List<osoba>();
  50.             SortedSet<osoba> bezduplikatow = new SortedSet<osoba>(new osoba());
  51.  
  52.             XmlSerializer serializer =
  53.     new XmlSerializer(typeof(List<osoba>));
  54.  
  55.             Stream reader = new FileStream(@"C:\Users\aa\Desktop\osoby.xml", FileMode.Open);
  56.  
  57.             lista = (List<osoba>)serializer.Deserialize(reader);
  58.  
  59.             foreach(osoba os in lista)
  60.             {
  61.                 bezduplikatow.Add(os);
  62.             }
  63.            ;
  64.  
  65.             FileInfo plik = new FileInfo(@"C:\Users\aa\Desktop\osoby.txt");
  66.             StreamWriter str = plik.CreateText();
  67.            // bezduplikatow.OrderBy(y => y.wiek)
  68.             foreach (osoba bd in bezduplikatow)
  69.             {
  70.                 str.WriteLine(bd.Id + ";" + bd.Imie + ";" + bd.Nazwisko + ";" + bd.wiek);
  71.             }
  72.             str.Close();
  73.            
  74.             Label1.Text = lista.Count + " " + bezduplikatow.Count;
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement