هنوز چند بایت مونده که پیدا کنم...

چسباندن دو دیکشنری با Concat در سی شارپ

بعضی وقتا لازمه که اطلاعات دو یا چندین دیکشنری را با هم ادغام کرد، برای اینکار، متد ()Concat، راه حل خوبیه.
// add group for all people
public static Dictionary<string, string> GroupDictionary
      =>
         new Dictionary<string, string>
         {
             ["ADMINISTRATOR"] = "Administrator",
             ["GUEST"] = "Guest"
         };

// add new item to group for special people 
public static Dictionary<string, string> SpecialGroupDictionary
{
    get
    {
       var specialGroup = new Dictionary<string, string>
       {
           ["CUSTOMER"] = "Customer",
           ["EMPLOYEE"] = "Employee"
       };

       // concat group and specific groups
       return
           specialGroup.Concat(GroupDictionary)
                       .ToDictionary(
                           groupDictionary => groupDictionary.Key,
                           groupDictionary => groupDictionary.Value);
   }
}

// call SpecialGroupDictionary
// return dictionary:

// Administrator
// Guest
// Customer
// Employee

نویسنده : فاطمه حسین پور
آدینه 27 آذر 1394
+ 10 -

خوشحال میشیم نظرتُ بدونیم