AddO1f

Seti_2

Apr 2nd, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using System;
  2. using System.Xml.Serialization;
  3. using System.IO;
  4.  
  5. public class Message
  6. {
  7.     public Person from;
  8.     public Person to;
  9.     public String text;
  10.     public int priority;
  11.     public Message() { }
  12.     public Message(Person person_from, Person person_to,string txt_text, int num_priority)
  13.     {
  14.         from = person_from;
  15.         to = person_to;
  16.         text = txt_text;
  17.         priority = num_priority;
  18.     }
  19. }
  20. public class Person
  21. {
  22.     public string name;
  23.     public string position;
  24.     public Person() { }
  25.     public Person(string txt_name, string txt_position)
  26.     {
  27.         name = txt_name;
  28.         position = txt_position;
  29.     }
  30. }
  31.  
  32. class Program
  33. {
  34.     static void Main(string[] args)
  35.     {
  36.         Message mes1 = new Message(new Person("Юстас", "шпион"),new Person("Алекс", "разведчик"), "Вторник. Новостей нет.", 3);
  37.         Message mes2 = new Message(new Person("Юстас", "шпион"), new Person("Алекс", "разведчик"), "Олег, где проект?", 4);
  38.  
  39.         StreamWriter writer = new StreamWriter("Message.xml");
  40.         XmlSerializer ser = new XmlSerializer(typeof(Message));
  41.         ser.Serialize(writer, mes1);
  42.         writer.Close();
  43.  
  44.         FileStream reader = new FileStream("Message.xml", FileMode.Open, FileAccess.Read);
  45.         XmlSerializer deser = new XmlSerializer(typeof(Message));
  46.         Message mes3 = (Message)deser.Deserialize(reader);
  47.  
  48.         Console.WriteLine("Сообщение от: " + mes3.from.name+ " " + mes3.from.position);
  49.         Console.WriteLine("к: " + mes3.to.name+ " " + mes3.to.position);
  50.         Console.WriteLine("текст: " + mes3.text);
  51.         Console.WriteLine("приоритет: " + mes3.priority);
  52.         Console.ReadKey();
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment