using System.Collections.Generic;
public static class Program
public static void Test<TMoma>(this TMoma moma) where TMoma : IMoma
var dict = new Dictionary<IMoma, string>();
Console.WriteLine("Can I find the moma KEY in the dictionary? " + dict.ContainsKey(moma));
var momaClone = JsonConvert.DeserializeObject<TMoma>(JsonConvert.SerializeObject(moma));
Console.WriteLine("Can I find the moma KEY in the dictionary using a cloned moma? " + dict.ContainsKey(momaClone));
Console.WriteLine("After I update moma's value, can I still find it in the dictionary? " + dict.ContainsKey(moma));
static void Main(string[] args)
Console.WriteLine("\r\nTesting with reference type---");
new ReferenceMoma() { Mo = "mo", Ma = 1 }.Test();
Console.WriteLine("\r\nTesting with value type---");
new ValueMoma() { Mo = "mo", Ma = 1 }.Test();
Console.WriteLine("\r\nWhy? :)");
public string Mo { get; set; }
public int Ma { get; set; }
class ReferenceMoma : IMoma
public string Mo { get; set; }
public int Ma { get; set; }