Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Xml.Serialization;
- using System.IO;
- public class Message
- {
- public Person from;
- public Person to;
- public String text;
- public int priority;
- public Message() { }
- public Message(Person person_from, Person person_to,string txt_text, int num_priority)
- {
- from = person_from;
- to = person_to;
- text = txt_text;
- priority = num_priority;
- }
- }
- public class Person
- {
- public string name;
- public string position;
- public Person() { }
- public Person(string txt_name, string txt_position)
- {
- name = txt_name;
- position = txt_position;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Message mes1 = new Message(new Person("Юстас", "шпион"),new Person("Алекс", "разведчик"), "Вторник. Новостей нет.", 3);
- Message mes2 = new Message(new Person("Юстас", "шпион"), new Person("Алекс", "разведчик"), "Олег, где проект?", 4);
- StreamWriter writer = new StreamWriter("Message.xml");
- XmlSerializer ser = new XmlSerializer(typeof(Message));
- ser.Serialize(writer, mes1);
- writer.Close();
- FileStream reader = new FileStream("Message.xml", FileMode.Open, FileAccess.Read);
- XmlSerializer deser = new XmlSerializer(typeof(Message));
- Message mes3 = (Message)deser.Deserialize(reader);
- Console.WriteLine("Сообщение от: " + mes3.from.name+ " " + mes3.from.position);
- Console.WriteLine("к: " + mes3.to.name+ " " + mes3.to.position);
- Console.WriteLine("текст: " + mes3.text);
- Console.WriteLine("приоритет: " + mes3.priority);
- Console.ReadKey();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment