Is it possible to create a truely weak-keyed dictionary in C#?

你说的曾经没有我的故事 提交于 2019-11-28 09:41:28
dtb

Have a look at the ConditionalWeakTable<TKey, TValue> Class.

Enables compilers to dynamically attach object fields to managed objects.

It's essentially a dictionary where both the key and the value are a WeakReference, and the value is kept alive as long as the key is alive.

Note! This class does not use GetHashCode and Equals to do equality comparisons, it uses ReferenceEquals.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!