Dictionary Initialization Syntax - CSharp Custom Type

CSharp examples for Custom Type:Object Initializer

Description

Dictionary Initialization Syntax

Demo Code

using System.Collections.Generic;
using System.ComponentModel;
class DictionaryInitialization
{
   static void Main()
   {/*  ww w.j av  a  2  s.c o m*/
      var objectInitializer = new Dictionary<string, int>
      {
         ["A"] = 20,
         ["B"] = 30,
         ["B"] = 40
      };
      var collectionInitializer = new Dictionary<string, int>
      {
         { "A", 20 },
         { "B", 30 },
         { "B", 40 }
      };
   }
}

Result


Related Tutorials