-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryLarge.cs
More file actions
53 lines (46 loc) · 1.51 KB
/
Copy pathBinaryLarge.cs
File metadata and controls
53 lines (46 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
namespace BLOBForReal
{
class Program
{
[Serializable]
public class ChessBoard
{
public string color = "";
public double squares = 0;
public string model = "";
public double price = 0;
public override string ToString()
{
return String.Format("A {0} chess set has {1} squares, costs {2}, and is the color {3}.", model, squares, price, color);
}
}
static void Main(string[] args)
{
ChessBoard theBest = new ChessBoard
{
color = "Blue",
squares = 64,
model = "Best Ever",
price = 13.99
};
IFormatter formatter = new BinaryFormatter();
//First I serialize
Stream stream1 = new FileStream("NewFile.bin", FileMode.Create, FileAccess.Write);
formatter.Serialize(stream1, theBest);
stream1.Close();
//Then I deserialize
Stream stream2 = new FileStream("NewFile.bin", FileMode.Open, FileAccess.Read);
ChessBoard theNextBest = (ChessBoard)formatter.Deserialize(stream2);
stream2.Close();
Console.WriteLine(theNextBest.ToString());
}
}
}