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.Text;
- using System.Threading.Tasks;
- using System.Xml.Serialization;
- namespace Michaล_Baran
- {
- [Serializable]
- class ListaOgloszen
- {
- public string nazwa;
- public Stack<Ogloszenie> ogloszenia;
- public ListaOgloszen(string nazwa)
- {
- this.nazwa = nazwa;
- ogloszenia = new Stack<Ogloszenie>();
- }
- public ListaOgloszen()
- {
- ogloszenia = new Stack<Ogloszenie>();
- }
- public string Nazwa { get => nazwa; set => nazwa = value; }
- public void DodajOgloszenie(Ogloszenie o)
- {
- ogloszenia.Push(o);
- }
- public string PodajOstatnie(int liczba)
- {
- Stack<Ogloszenie> wynik = new Stack<Ogloszenie>();
- int x = ogloszenia.Count;
- for (int i = 0; i <= x; i++)
- {
- var item = ogloszenia.ElementAt(x);
- wynik.Push(item);
- }
- StringBuilder sb = new StringBuilder();
- foreach (Ogloszenie o in wynik)
- {
- sb.AppendLine(o.ToString());
- }
- return sb.ToString();
- }
- //public string ZnajdzOgloszenie(string slowo)
- //{
- // return ogloszenia.First<>
- //}
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- foreach (Ogloszenie o in ogloszenia)
- {
- sb.AppendLine(o.ToString());
- }
- return sb.ToString();
- }
- public static void ZapiszXML(string nazwa, ListaOgloszen z)
- {
- XmlSerializer serializer = new XmlSerializer(typeof(ListaOgloszen));
- StreamWriter writer = new StreamWriter(nazwa);
- serializer.Serialize(writer, z);
- writer.Close();
- }
- public static ListaOgloszen OdczytajXML(string nazwa)
- {
- XmlSerializer serializer = new XmlSerializer(typeof(ListaOgloszen));
- using (StreamReader reader = new StreamReader(nazwa))
- {
- ListaOgloszen wynik = serializer.Deserialize(reader) as ListaOgloszen;
- return wynik;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement