Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Runtime.Serialization.Formatters.Binary;
- namespace xmlapp
- {
- class Program
- {
- static void Main(string[] args)
- {
- Player pl0 = new Player(27, "Sam", "Halleman");
- Player pl1 = new Player(24, "Dairysh", "none");
- BinaryFormatter formatter = new BinaryFormatter();
- byte[] data;
- MemoryStream stream = new MemoryStream();
- formatter.Serialize(stream, pl0);
- formatter.Serialize(stream, pl1);
- data = stream.ToArray();
- MemoryStream ms = new MemoryStream(data);
- Player pl0ds = (Player)formatter.Deserialize(ms);
- Player pl1ds = (Player)formatter.Deserialize(ms);
- }
- }
- [Serializable]
- public class Player
- {
- private int age;
- private string name;
- [NonSerialized]
- private string surname;
- public int Age
- {
- get { return this.age; }
- }
- public string Name
- {
- get { return this.name; }
- }
- public string SurName
- {
- get { return this.surname; }
- }
- public Player(int age, string name, string surname)
- {
- this.age = age;
- this.name = name;
- this.surname = surname;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement