+ 5

[Solved:]Does Sololearn support dictionary initialization syntax in c#?...

[EDIT: Yes it does] ... or am I just doing it wrong (the latter being the likely answer 😂). I have googled, stackoverflowed, etc to see what I am doing wrong. I am new to C#, lesson and coding challenges here in Sololearn. Here is a snippet of the code with a print to see if data is getting in the dictionary. static void Main(string[] args) { var months = new Dictionary<string, string> { {"January","1"}, {"February","2"}, {"March","3"}, {"April","4"}, {"May","5"}, {"June","6"}, {"July","7"} }; Console.WriteLine(months[" April"]); } The error I get is that there is no April key in the dictionary. I am working on the US to EU date conversion solution. I am wondering if it is a .Net version issue. I noted in my searching that some older versions like 2.0 don't support initializer syntax.

21st Jan 2020, 7:19 PM
Paul K Sadler
Paul K Sadler - avatar
4 odpowiedzi
+ 5
A little bit off-topic but if you copied this from your code I see a space before April in the WriteLine line. Edit. I just checked it is the space...
21st Jan 2020, 7:39 PM
Mihai Apostol
Mihai Apostol - avatar
+ 4
The code is fine and runs on SoloLearn, the issue is the same what Mihai Apostol mentioned. Pay attention there is no whitespace inside the quotation marks.
21st Jan 2020, 7:45 PM
Tibor Santa
Tibor Santa - avatar
+ 4
😂😂🤣 Mihai Apostol Tibor Santa I told you it was probably me doing it wrong! In portrait mode on my phone it broke the line right at April, so I never caught it. When I read your answer and rotated the phone I saw the space. Thanks for the debug assist! I spent hours trying to find an answer to that issue.
21st Jan 2020, 7:52 PM
Paul K Sadler
Paul K Sadler - avatar
+ 3
You're welcome.
21st Jan 2020, 7:53 PM
Mihai Apostol
Mihai Apostol - avatar