using System.Runtime.Serialization.Formatters.Binary;
using System.Collections.Generic;
public static class DictionaryExtension
public static byte[] Serialize<T,V>(this Dictionary<T,V> source)
using (var memoryStream = new MemoryStream())
var binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(memoryStream, source);
return memoryStream.ToArray();
public static void Main()
var foo = new Dictionary<int,bool>()
var res = foo.Serialize();