Created
June 14, 2018 09:27
-
-
Save avitsidis/9d172a59da326d1d78015687a2be1e06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.Serialization.Formatters.Binary; | |
using System.Runtime.Serialization; | |
using System.IO; | |
namespace ConsoleApp | |
{ | |
[Serializable] | |
class MyClass | |
{ | |
private DateTime? myDate; | |
public DateTime? MyDate | |
{ | |
get{return myDate;} | |
set | |
{ | |
if (myDate != value) | |
{ | |
myDate = value; | |
} | |
} | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
IFormatter formatter = new BinaryFormatter(); | |
var memoryStream = new MemoryStream(); | |
var myclasses = new MyClass[] { | |
new MyClass{ MyDate = DateTime.Today }, | |
new MyClass{ MyDate = null } | |
}; | |
formatter.Serialize(memoryStream,myclasses); | |
memoryStream.Position = 0; | |
var myclasses2 = (MyClass[])formatter.Deserialize(memoryStream); | |
foreach (var myclass in myclasses2) | |
Console.WriteLine(myclass.MyDate); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment