Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset a Dictionary

Tags:

c#

dictionary

If I declared a dictionary like this:

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

And now I want to use it at another place. How do I reset it?

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

or other reset styles?

like image 675
Nano HE Avatar asked Dec 30 '09 07:12

Nano HE


People also ask

How do you unset a dictionary?

dict unset unsets one element from the dictionary of dictionaries named dictVarName. They key arguments form a path to the key to unset. The variable is modified, and its new value is returned. If the given key doesn't exist in the dict, no change is made.

What does Clear () do in Python?

The clear() method removes all the elements from a list.

How do I delete an entire dictionary?

Python has in-built clear() method to delete a dictionary in Python. The clear() method deletes all the key-value pairs present in the dict and returns an empty dict.


2 Answers

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(); 
like image 185
Christian C. Salvadó Avatar answered Oct 26 '22 02:10

Christian C. Salvadó


Try this

aDict.Clear(); 
like image 27
Anuraj Avatar answered Oct 26 '22 02:10

Anuraj