Logo

Programming-Idioms

History of Idiom 8 > diff from v72 to v73

Edit summary for version 73 by nu8:
[C#] syntax is simply not correct

Version 72

2020-05-03, 08:28:31

Version 73

2020-10-08, 03:18:27

Idiom #8 Initialize a new map (associative array)

Declare a new map object x, and provide some (key, value) pairs as initial content.

Idiom #8 Initialize a new map (associative array)

Declare a new map object x, and provide some (key, value) pairs as initial content.

Variables
x
Variables
x
Extra Keywords
table dictionary hash
Extra Keywords
table dictionary hash
Imports
System.Collections.Generic
Imports
System.Collections.Generic
Code
Dictionary<int, string> x = new Dictionary<int, string>()
{
    (1, "Value1"),
    (2, "Value2")
};
Code
var m = new Dictionary<string, int>() {
   {"year", 2019}, {"month", 12}
};
Comments bubble
Example uses collection initializer. To add manually, use:

x.Add(1, "Value1");
Comments bubble
Example uses collection initializer. To add manually, use:

x.Add(1, "Value1");
Doc URL
https://msdn.microsoft.com/en-us/library/xfhwa508%28v=vs.110%29.aspx
Doc URL
https://msdn.microsoft.com/en-us/library/xfhwa508%28v=vs.110%29.aspx
Demo URL
https://nu8.github.io/autumn/declare-map/c-sharp