Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Merge Sample
//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; namespace Rextester { public class Program { public static void Main(string[] args) { List<Scan> savedScans = new List<Scan>(); savedScans.Add(new Scan() {ID=1, Code=1234, Event = 1}); savedScans.Add(new Scan() {ID=5, Code=567, Event = 1}); savedScans.Add(new Scan() {ID=8, Code=89, Event = 1}); savedScans.Add(new Scan() {ID=10, Code=11, Event = 1}); List<Scan> newScans = new List<Scan>(); newScans.Add(new Scan() {ID=2, Code=1234, Event = 1}); newScans.Add(new Scan() {ID=4, Code=567, Event = 1}); newScans.Add(new Scan() {ID=8, Code=89, Event = 1}); newScans.Add(new Scan() {ID=9, Code=10, Event = 1}); newScans.Add(new Scan() {ID=11, Code=1234, Event = 2}); var a = savedScans.Concat(newScans).ToLookup(s => new {code = s.Code, ev = s.Event}).Select(g => g.Aggregate((s, n) => s.ID > n.ID ? s : n)).OrderBy(t => t.Code).ToList(); Console.WriteLine(a.Count); Console.WriteLine(a[0].ID + " Code:" + a[0].Code+ " Event:" + a[0].Event); Console.WriteLine(a[1].ID + " Code:" + a[1].Code+ " Event:" + a[1].Event); Console.WriteLine(a[2].ID + " Code:" + a[2].Code+ " Event:" + a[2].Event); Console.WriteLine(a[3].ID + " Code:" + a[3].Code+ " Event:" + a[3].Event); Console.WriteLine(a[4].ID + " Code:" + a[4].Code+ " Event:" + a[4].Event); Console.WriteLine(a[5].ID + " Code:" + a[5].Code+ " Event:" + a[5].Event); } } public class Scan { public int ID; public int Code; public int Event; } }
run
|
edit
|
history
|
help
0
concat
Lambdas
nums y lists
,
C Triangle
IF... ELSE
v3
obrazek
RightSideView Tree
mo3dal