Sunday, February 13, 2011

Initializing a Dictionary of List with the Dynamic Sugar library in C#

The Dynamic Sugar Sharp library is all about syntactic sugar. Here is one example.

I want to initialize a Dictionary containing a key and a List.

In standard C#

var dic1 = new Dictionary<string, List<int>>() { 

  { "L1" , new List<int>() { 1,2,3 } },
  { "L2" , new List<int>() { 1,2,3 } },
};

In C# with Dynamic Sugar

var dic2 = DS.Dictionary(
                
  L1:DS.List(1,2,3),
  L2:DS.List(1,2,3)
);

1 comment: