Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Full join
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
using System; using System.Collections.Generic; using System.Linq; namespace Rextester { public class Program { class Korv { public string Name; public List<int> Items; } public static void Main(string[] args) { List<Korv> list1 = new List<Korv> { new Korv() { Name = "abc", Items = new List<int>{ 2, 6, 9 } }, new Korv() { Name = "def", Items = new List<int>{ 1, 5, 8 } }, new Korv() { Name = "ghf", Items = new List<int>{ 1, 5, 8 } }, }; List<Korv> list2 = new List<Korv> { new Korv() { Name = "abc", Items = new List<int>{ 4, 11, 14 } }, new Korv() { Name = "def", Items = new List<int>{ 5, 12, 15 } }, new Korv() { Name = "xyz", Items = new List<int>{ 16, 17, 18 } } }; HashSet<string> joinedNames = new HashSet<string>(); var joined = list1.Join(list2, x => x.Name, x => x.Name, (a, b) => { joinedNames.Add(a.Name); return new Korv() { Name = a.Name, Items = a.Items.Concat(b.Items).ToList() }; }); var everything = joined.Union(list1.Where(x => joinedNames.Contains(x.Name) == false)).Union(list2.Where(x => joinedNames.Contains(x.Name) == false)); Console.WriteLine(string.Join(Environment.NewLine, everything.Select(x => x.Name + " - " + string.Join(",", x.Items.Select(y => y.ToString()))))); } } }
Show compiler warnings
[
+
]
Show input
Compilation time: 0,17 sec, absolute running time: 0,13 sec, cpu time: 0,14 sec, average memory usage: 14 Mb, average nr of threads: 3
edit mode
|
history
|
discussion
abc - 2,6,9,4,11,14 def - 1,5,8,5,12,15 ghf - 1,5,8 xyz - 16,17,18