How to load values into Dictionary using { }

.net, c#, dictionary

Solution

This is working:

Dictionary<byte, byte> dict = new Dictionary<byte, byte>() { { 1, 1 }, { 2, 2 } };

Problem

Is is possible to load values into Dictionary using { } ? This fails ``` static Dictionary<byte, byte> dict = new Dictionary<byte, byte>() { new KeyValuePair<byte, byte>(1, 1) }; ``` This does not fail so I suspect there is syntax for loading in { } ``` static Dictionary<byte, byte> dic1252expand = new Dictionary<byte, byte>() { }; ``` This is sample syntax that works ``` byte[] bytes = new byte[] { 1, 2, 3 }; KeyValuePair<byte, byte> kvp = new KeyValuePair<byte, byte>(1, 1); ```

Original source