I have piece of code as below:
IDictionary<string, string> dictionary = new Dictionary<string, string>(){
{ "de-DE", "German"},
{ "en‐GB", "English"},
{ "en‐US", "English"},
{ "es‐ES", "Spanish"},
{ "es‐MX", "Spanish"},
{ "fr‐CA", "French"},
{ "fr‐FR", "French"},
{ "hu‐HU", "Hungarian"},
{ "pl‐PL", "Polish"},
{ "pt‐PT", "Portuguese"},
{ "nl‐NL", "Dutch"},
{ "nb‐NO", "Norwegian"},
{ "sv‐SE", "Swedish"},
{ "it‐IT", "Italian"},
};
bool check = dictionary.ContainsKey("en-US");
Console.WriteLine(check);
The check
returns false
.
Could someone help to explain it?
Your dashes aren't the same. Take a look at what your text looks like in Notepad++ (useful when you need to debug character related stuff like this):
After replacing your dash with an actual -
, the code works as expected.
EDIT
Thanks, @Scott Chamberlain for the .net fiddle that highlights the character differences.
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