- Published on
C# - 6.0 Index Initializers
Before C# 6
static void Main ( string [ ] args )
{
var dic = new Dictionary<int, string>();
dic.Add( 1, "Cash" );
dic.Add( 2, "Mary" );
}
//or
static void Main ( string [ ] args )
{
var dic = new Dictionary<int, string>()
{
{ 1, "Cash" },
{ 2, "Mary" }
};
}
C# 6
static void Main ( string [ ] args )
{
var dic = new Dictionary<int , string>()
{
[1] = "Cash",
[2] = "Mary"
};
}