Creating a constant Dictionary in C#
Posted
by David Schmitt
on Stack Overflow
See other posts from Stack Overflow
or by David Schmitt
Published on 2008-11-06T09:38:22Z
Indexed on
2010/04/18
17:03 UTC
Read the original article
Hit count: 1068
What is the most efficient way to create a constant (never changes at runtime) mapping of string
s to int
s?
I've tried using a const Dictionary, but that didn't work out.
I could implement a immutable wrapper with appropriate semantics, but that still doesn't seem totally right.
For those who have asked, I'm implementing IDataErrorInfo in a generated class and am looking for a way to make the columnName lookup into my array of descriptors.
I wasn't aware (typo when testing! d'oh!) that switch accepts strings, so that's what I'm gonna use. Thanks!
© Stack Overflow or respective owner