- Home /
does the static keyword work on generic dictionary
does the static keyword work on all variable types, including generic dictionary?
Answer by $$anonymous$$ · Dec 26, 2012 at 04:34 PM
of course, datatype of the variable does not matter in this case. You are free to declare a generic dictionary static. This could have been tested quickly just by compiling an example.
are you sure your generic dictionary is being updated with values? it doesn't seem to work all the time
Absolutely, there is no restrictions on the use of the static keyword in the C# language :) It can be used on types and type members. The modifier does not impose any restrictions on any specific kind of datatype. If there is an inconsistency it is most surely a problem with the logic which is modifying it. A generic dictionary is a reference type, and the static keyword does not have any problems with this, just like you can create a static reference of any of your own objects, or things like generic lists and such, it does not treat any of them differently.
Answer by Setzer22 · Dec 26, 2012 at 03:36 PM
I can't tell you specifically for the generic dictionary. But it works on generic lists as well as queues, so I would say it does work on dictionaries too.
Other than that I don't remember any case where you can't declare a variable static
Your answer
![](https://koobas.hobune.stream/wayback/20220613085939im_/https://answers.unity.com/themes/thub/images/avi.jpg)