Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fórum ➡ Aggregating 2 compatible dictionaries, using LINQ ♦
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; // aljodav // http://rextester.com/users/376 // in reply to this MSDN thread: // http://bit.ly/2eQtTQm namespace Rextester { using Dic=Dictionary<string,List<int>>; using Li=List<int>; public class Program { public static Dic GetDic1() { return new Dic(){ {"kkk",new Li{999,888,}}, {"cc",new Li{33,34,35,}}, {"jj",new Li{10,11,20,21,}}, {"hh",new Li{57,59,}} }; } public static Dic GetDic2() { return new Dic{ {"zzz",new Li{441,442,443,444,}}, {"jj",new Li{22,12,}}, {"kkk",new Li{555,666,777,}}, {"hh",new Li{55,53,51,}} }; } public static void Main(string[] args) { Dic d1=GetDic1(),d2=GetDic2(); d1=d2.Aggregate(d1,(x,y)=>{ if(x.ContainsKey(y.Key)){x[y.Key].AddRange(y.Value);} else{x.Add(y.Key,y.Value);} return x; }); foreach(var v in d1){ Console.WriteLine("\n\n{0} ↔",v.Key); foreach(var w in v.Value){ Console.WriteLine("\t"+w); } } } } }
run
|
edit
|
history
|
help
0
aba
Create Sealed Class Object
C# Bubble Sort
BFS DFS stack vs recursive
text
Check if string is palindrome
Bases5
teste
problem_name
Sum Matrix Row