Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fórum ➡ GroupJoin ➡ Join ➡ Easily ‼
//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 namespace Rextester { class Lead{public int Id;public string Name,Phone,Address;} class LeadProg{public int Id,PrgId;} class Prog{public int PrgId;public string Prg;} class Program { static IEnumerable<Prog> GetProgs(){ return new List<Prog>{ new Prog{PrgId=1,Prg="A qwe"}, new Prog{PrgId=2,Prg="B asd"}, new Prog{PrgId=3,Prg="C zxc"}, new Prog{PrgId=4,Prg="D rty"}, new Prog{PrgId=1,Prg="E fgh"}, new Prog{PrgId=2,Prg="F vbn"}, new Prog{PrgId=3,Prg="G poi"}, new Prog{PrgId=1,Prg="H lkj"}, new Prog{PrgId=2,Prg="I mnb"}, new Prog{PrgId=1,Prg="J qaz"}, new Prog{PrgId=5,Prg="K wsx"}, new Prog{PrgId=6,Prg="L edc"}, }; } static IEnumerable<LeadProg> GetLeadProgs(){ return new List<LeadProg>{ new LeadProg{Id=1,PrgId=3}, new LeadProg{Id=2,PrgId=12345}, new LeadProg{Id=3,PrgId=1}, new LeadProg{Id=4,PrgId=4}, new LeadProg{Id=5,PrgId=6}, new LeadProg{Id=6,PrgId=5}, new LeadProg{Id=7,PrgId=2}, }; } static IEnumerable<Lead> GetLeads(){ return new List<Lead>{ new Lead{Id=1,Name="mae",Phone="999",Address="Qwe St"}, new Lead{Id=2,Name="ray",Phone="888",Address="Rty St"}, new Lead{Id=3,Name="ann",Phone="777",Address="Asd St"}, new Lead{Id=4,Name="jim",Phone="666",Address="Fgh St"}, new Lead{Id=5,Name="kim",Phone="555",Address="Zxc St"}, new Lead{Id=6,Name="tim",Phone="444",Address="Vbn St"}, new Lead{Id=7,Name="may",Phone="333",Address="Zaq St"}, }; } public static void Main(string[] args) { IEnumerable<LeadProg> outer=GetLeadProgs(); IEnumerable<Prog> inner1=GetProgs(); IEnumerable<Lead> inner2=GetLeads(); Console.WriteLine("LeadId Name Phone Address ( Programs below )\n"); outer .GroupJoin( inner1, lead=>lead.PrgId, prg=>prg.PrgId, (lead,prgs)=>new{ LeadId=lead.Id, Programs=prgs.Select(x=>x.Prg) }) .Join( inner2, groupjoin=>groupjoin.LeadId, lead=>lead.Id, (groupjoin,lead)=>new{ LeadId=lead.Id, Name=lead.Name, Phone=lead.Phone, Address=lead.Address, Programs=groupjoin.Programs }) .ToList() .ForEach(x=>{ Console.WriteLine("\n{0,6} {1,-4} {2,-5} {3}\n",x.LeadId,x.Name,x.Phone,x.Address); x.Programs.ToList().ForEach(y=>Console.WriteLine("\t{0}",y)); }); Console.WriteLine("\n\nHello, world!"); } } }
run
|
edit
|
history
|
help
0
Planet-D ver. 0.7
12345
xml into dictionary
stackoverflow_25444818
Frase
1
asxsdxsd
Ejemplos polimorfismos con interfaces y posibles usos sencillos c#
Can a == true && a == false be true in C#?
Dijkstra’s shortest path algorithm