Skip to content

Instantly share code, notes, and snippets.

@avitsidis
Created June 14, 2018 09:27
Show Gist options
  • Save avitsidis/9d172a59da326d1d78015687a2be1e06 to your computer and use it in GitHub Desktop.
Save avitsidis/9d172a59da326d1d78015687a2be1e06 to your computer and use it in GitHub Desktop.
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