如何重置字典 [英] How to reset a Dictionary

查看:128
本文介绍了如何重置字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我宣布这样一个字典

If I declared a dictionary like this.

private static Dictionary<string, object> aDict = new Dictionary<string, object>();

和我仍然想在别的地方使用它。 ?如何重置

And i still want to use it at another place. How to reset it?

aDict = new Dictionary<string, object>(); // like this?

aDict = null; // Like this ?

或其他复位样式?谢谢你。

or other reset styles? THANK YOU.

我喜欢的网站,

感谢各位。

推荐答案

您可以简单地使用的清除方法,它会删除所有键和值,那么你就可以重新使用它,而无需创建新实例:

You can simply use the Clear method, it will remove all keys and values, then you can reuse it without having to create new instances:

aDict.Clear();

这篇关于如何重置字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆