var myObject = new MyObject(); var data = new ExtraData(); var dict = new ConditionalWeakTable(); dict.Add(myObject, data);
var myObject = new MyObject(); var dict = new ConditionalWeakTableIn this example, we create a weak reference to an object of type MyObject, and then add it to a list of weak references in a ConditionalWeakTable. This allows us to track all the references to the object, and remove them when the object is no longer in use. The ConditionalWeakTable class is part of the System.Runtime.CompilerServices namespace in the .NET Core library.