score:21
Accepted answer
Use SelectMany
. See http://msdn.microsoft.com/en-us/library/bb534336.aspx
score:1
var result = ListOfLists.SelectMany(v => v).ToList().Distinct();
EDIT: For better performance, use:
var result = ListOfLists.SelectMany(v => v).Distinct();
or
var result = ListOfLists.SelectMany(v => v).Distinct().ToList();
score:5
For completeness, the query expression syntax is sometimes easier (I find) to come up with than the correct invocation of SelectMany
. Here it would be:
result = (from list in ListOfLists
from s in list
select s).Distinct().ToList();
score:13
var distinctStrings = ListOfLists.SelectMany(list => list).Distinct();
Source: stackoverflow.com
Related Query
- Union A List of Lists Using Linq
- Remove duplicates while merging lists using Union in LINQ
- Using Linq and C#, trying to get two lists from a list of master items grouped by two inner lists
- Using Linq to compare a list with a set of lists in C#
- List generation from list containing lists using Linq
- Get the count of distinct elements from a list of lists using LINQ
- Converting a list of lists into a single list using linq
- How to join a list of lists in a unique list using Linq
- Using LINQ how to transform a List of Lists using elements index
- LINQ - Sort List of objects using OrderBy EnumValue, and Union result set?
- List of EF objects to Dictionary of lists using linq
- Best way to join 3 lists and count how many times an ID is in the list using linq
- LINQ C# Calculating a List value using 2 lists
- Reduce a list into smaller lists of two using LINQ (Functional Programming)
- How to group a list of lists using LINQ (ex: List<List<int>>)
- Order a list of lists in C# using LINQ
- Using LINQ to return List from 2 lists
- Merging lists in another list using LINQ c#
- How to Group and Sum List of Lists using Linq
- using linq to orderBy in list of lists
- Get information relevant to user using LINQ on Object list ( Combined lists )
- How to get lists of X and Y from a list of points using a single linq query?
- Aggregating Lists inside of a List of objects using LINQ
- Converting this List of Lists to Dictionary using LINQ
- Sort list of lists using LINQ so high score is first then lastname and firstname in alphabetic order
- Construct a list of wpf Hyperlink elements from an XML source file using Linq
- Using Linq to do: Compile a list of all lists within a list of objects
- Using linQ to group list of object into new lists of objects
- Getting Count of the first list from joined two lists using Linq C#
- Return select objects and only desired subvalues from a list of lists using LINQ
More Query from same tag
- How to Improve on this Entity Framework Query
- Entity Framework loading foreign keys with HasOptional
- How to append an array to a List using LINQ?
- Linq query takes far too long
- C# Linq Left Outer Join WHERE clause
- LINQ QueryProvider Select
- Better Way to Check for Null Value in Linq Path
- C# Code Optimization GroupBy
- how to groupby and custom calculate in linq to Entity Framework?
- Linq deferred execution with local values
- Entity Framework Core LINQ Class Property/Methods can't use Included Property
- Entity Framework, DbSet<T>, Dispose() performance questions
- LINQ how to project a list while combining properties of object
- Dynamically building an expression tree
- Using ToList() on Enumerable LINQ query results for large data sets - Efficiency Issue?
- how to get table data in json using linq and entityframework
- Compare two Lists by specific properties
- Create Generic Type with Generic Interface at Run Time
- String search in List<T> with high performance
- how to compare a list type of object with list type int
- how to use left join in linq
- ObjectContext Closed error when using Include?
- Linq receiving unable to create value type of model, only primitive types or enumeration types are supported
- Lambda expression not correct - need to return a boolean Func
- Grouping lambda
- Linq.NHibernate problem with OR statement
- Order by date and convert to string In list
- Multiple filter Searching without having multiple options -ASP.NET MVC
- How much is too much data for and XML file, and what are some file based database alternatives?
- What LINQ operation related to Paging could be slowing down my query?