如何重置字典
如果我宣布这样的字典:
private static Dictionary aDict = new Dictionary();
现在我想在另一个地方使用它。 我该如何重置它?
aDict = new Dictionary(); // like this? aDict = null; // or like this?
或其他重置样式?
您可以简单地使用Clear方法,它将删除所有键和值,然后您可以重用它而无需创建新实例:
aDict.Clear();
试试这个
aDict.Clear();
aDict.Clear();
将工作。
aDict.Clear();
是唯一的方法,因为您不想更改引用并在另一个地方保持相同的对象可用