Search code examples
c#.netmultithreadingcollectionsconcurrent-collections

Is there an equivalent for Java WeakHashMap class in C#?


Is there a C# class that provides map with weak keys or/and weak values? Or at least WeakHashMap like functionality.


Solution

  • In .Net 3.5 and below, there is no such structure available. However I wrote up one for a side project and posted the code at the following location.

    Starting .NET 4.0, there is a structure available called ConditionalWeakTable in the Runtime.CompilerServices namespace that also does the trick.