now that this has been clarified, the question is basically this:
- combine all elements from list a and list b, and if there are any duplicates, keep the one with the newest
i would do this with a grouping:
var players = from p in lista.concat(listb) group p by p.id into g select g.orderbydescending(x => x.lastgameplayed).first();
if performance is an issue, there are "faster" ways to write this, but i would start with this.
you can write an o(n log n) solution by building a set from list2 then overwriting (or inserting) items with list1, then converting that set back to a list.
if the lists are already sorted, you could do it o(n) by merging by hand.
you should be able to use the linq enumerable extension concat and exept to achieve this.
this will remove items in b that match a, and them add the result to a.
you will have to write an iequalitycomparer which compares by id.
documentation for theses methods can be found here:
iequalitycomparer documentation can be found here:
- Combining lists but getting unique members
- Getting distinct and ordered members from a list of strings - linq or hashset for unique which one is faster / better suited
- Combining a list of objects with periods into unique lists
- I'm trying to convert a SQL query to linq, but I'm getting stuck on combining group by and max()
- Unique object counts are not getting counted in form of String but char
- Getting Value cannot be null. parameter name: source on release but not in debug
- LINQ Partition List into Lists of 8 members
- Combining Lists in Lambda/LINQ
- Getting unique values from a list of objects with a List<string> as a property
- LINQ Getting Unique items from a List within a List
- Combining 2 lists and and remove duplicates .Output in a third list .My attempts do not work
- LINQ Source Code Available
- Combining child class lists to parent class list
- C# Code Contracts -- How to ensure that a collection of items contains items with unique properties?
- .NET 4 Code Contracts: "requires unproven: source != null"
- Using Linq and C#, is it possible to join two lists but with interleaving at each item?
- SQL Trigger is trying to insert a null value but my C# code is passing int 300?
- Getting the difference between two Lists based on certain fields
- EF code first - getting DynamicProxies instead of objects. Why?
- How to join a list of lists in a unique list using Linq
- Divide a single List of Class Objects into multiple Lists based on Class Members C#
- Get all members that do not match between 2 lists
- Merge equal items with multiple lists but different length
- Exception in System.Data.Entity.dll but was not handled in user code
- creating Linq to sqlite dbml from DbLinq source code
- Combining two datatable and getting the amount from second table by using linq
- Combining lists in linq
- Getting value as DateTime, but displaying as DateTime.Year in DropDownList (with LINQ)
- Getting the Total Number of Elements From All Lists Belonging to An Object
- Merging 2 lists with linq based on unique Id to avoid duplicates
More Query from same tag
- LINQ: Search multiple fields of a List of objects where fields can be null
- Why am I getting a null exception when trying to assign a value to a nested object in C# asp.net 5?
- object references in LINQ to SQL are incorrectly saved or loaded
- grouping the list object with where clauses and return
- use linq to find item in list of arrays
- Lambda expression to create AND filter
- How to improve loop Xdocument
- EF/LINQ : Find() operation
- Given UIElementCollection, find all elements that have StyleA, and change them to StyleB in WPF
- using Comparer to sort IEnumerable in C# by different fields
- Linq to produce custom period in days, hours, minutes and seconds
- Check if any XML nodes exists with Specific Attribute using LINQ C#
- How can I bind the single LINQ object to ASP.NET Repeater Control
- How To add another constructor with parameter in linq class(Table)
- LINQ sum and groupby and return empty records?
- XDocument from string has one element, need toDictionary
- Linq query for dynamically value
- Dynamic grouping based on filters in Linq
- Creating a hierarchical structure from a list of sequence strings
- linq2db "cannot be converted to sql" error
- c# Linq - Get all elements that contains a list of integers
- C# Linq Query - Extracting multiple groups from a collection (nested groups?)
- Purpose of EF 6.x DbContext Generator option when adding a new data item in Visual Studio
- Convert LINQ returned value to 2D Array
- Select new object from IQueryable returns part of list in a case
- Loop recursive self join table
- Too many database calls when mapping to ViewModel
- Custom compare dictionaries linq
- Peta Poco where clause
- how to find corresponding item and value from class list