Intializing dictionary in c# 3.0

Posted by Casey on Stack Overflow See other posts from Stack Overflow or by Casey
Published on 2010-05-08T02:05:13Z Indexed on 2010/05/08 2:08 UTC
Read the original article Hit count: 186

Filed under:

I'm having trouble with the following collections initalization:

private Dictionary<string, string> mydictionary = new Dictionary<string, string>()
{
    {"key", "value"}
    , {"key2", "value2"}
    , {"key3", "value3"}
};

I keep getting various compiler errors about the syntax. From what I have googled this should be perfectly valid C# 3.0 code.

The first error that pops up is:

Error   102 ; expecte

What am I doing wrong?

© Stack Overflow or respective owner

Related posts about c#