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.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Xml;
- using System.Xml.Serialization;
- namespace zad3
- {
- public partial class WebForm1 : System.Web.UI.Page
- {
- public class osoba : IComparer<osoba> //: IEqualityComparer<osoba>
- {
- public int Id;
- public string Imie;
- public string Nazwisko;
- public int wiek;
- /* public bool Equals(osoba a1, osoba a2)
- {
- if (a1.Id == a2.Id && a1.Imie == a2.Imie && a1.Nazwisko == a2.Nazwisko && a1.wiek == a2.wiek)
- return true;
- else
- return false;
- }
- public int GetHashCode(osoba oso)
- {
- return 0;
- }*/
- public int Compare(osoba a1, osoba a2)
- {
- if (a1.Id == a2.Id && a1.Imie == a2.Imie && a1.Nazwisko == a2.Nazwisko && a1.wiek == a2.wiek)
- return 0;
- if (a1.wiek < a2.wiek)
- return -1;
- else
- return 1;
- }
- }
- protected void Page_Init(object sender, EventArgs e)
- {
- List<osoba> lista = new List<osoba>();
- SortedSet<osoba> bezduplikatow = new SortedSet<osoba>(new osoba());
- XmlSerializer serializer =
- new XmlSerializer(typeof(List<osoba>));
- Stream reader = new FileStream(@"C:\Users\aa\Desktop\osoby.xml", FileMode.Open);
- lista = (List<osoba>)serializer.Deserialize(reader);
- foreach(osoba os in lista)
- {
- bezduplikatow.Add(os);
- }
- ;
- FileInfo plik = new FileInfo(@"C:\Users\aa\Desktop\osoby.txt");
- StreamWriter str = plik.CreateText();
- // bezduplikatow.OrderBy(y => y.wiek)
- foreach (osoba bd in bezduplikatow)
- {
- str.WriteLine(bd.Id + ";" + bd.Imie + ";" + bd.Nazwisko + ";" + bd.wiek);
- }
- str.Close();
- Label1.Text = lista.Count + " " + bezduplikatow.Count;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement