I'm wondering if there is a way to put all dictionary values to null (or each elements) ? Because we can't iterate on it if the values has been changed to null.
(I've searched on Stackoverflow before asking this simple question but I didn't find a clear response on this issue).
Regards
Is this what you want?
foreach(var key in dict.Keys.ToList())
dict[key] = null;
Important: The call to ToList()
. This will copy the keys to a temporary list. Otherwise you would get an InvalidOperationException
with the message:
Collection was modified; enumeration operation may not execute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With