score:17
Accepted answer
var result =
from x in xs
group xs by x into grp
where grp.count() == 1
select grp.key;
like that?
50seconds too late ... :/
score:0
various extension methods you could use:
public static ienumerable<t> whereunique<t>(this ienumerable<t> items)
{
return items.groupby(x => x).where(x => x.count() ==1).select(x => x.first());
}
possibly slightly more performant, depending on the distribution of your data:
public static ienumerable<t> whereunique<t>(this ienumerable<t> items)
{
return items.groupby(x => x).where(x => !x.skip(1).any()).select(x => x.first());
}
and whereuniqueby, which works similiar to morelinqs distinctby()
:
public static ienumerable<t> whereuniqueby<t, tselector>(this ienumerable<t> items, func<t, tselector> func)
{
return items.groupby(func).where(x => x.count() ==1).select(x => x.first());
}
score:11
list.groupby(i => i)
.where(g => g.count() == 1)
.select(g => g.first());
Source: stackoverflow.com
Related Query
- Get all elements that only occur once
- LINQ: Select Elements that Only Appear Once in a List
- Get a count of elements that appear once in a list with LINQ
- c# Linq - Get all elements that contains a list of integers
- How to get records if only all of the list elements included in nested collections?
- How Get back all "Customer" objects and only their "Order"s that are "Open" in Linq to SQL?
- What Linq function can i use to get all the combination sequences of two Enumerables that choose between the two elements of every index?
- Get all elements but the first from an array
- Is there an IEnumerable implementation that only iterates over it's source (e.g. LINQ) once?
- Getting head and tail from IEnumerable that can only be iterated once
- Trying to get all elements after first match using linq
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- How to get all elements except the n'th element in a List using Linq
- Given UIElementCollection, find all elements that have StyleA, and change them to StyleB in WPF
- Using Linq, get all items from list that are in another List<int>
- SQL to LINQ to get all records that match all values
- How can I get the average of the elements of a generic list that meet a criteria?
- Get all members that do not match between 2 lists
- How to get all elements from linq query?
- Linq Entity Framework - get all customers that Ids are not in many to many table
- IEnumerable: Get all before the last that matches a predicate
- Linq - Get all items between 2 matching elements
- Using Linq to loop through all controls only get the first control
- LINQ get elements from one collection that don't belong to another
- How to get all elements out of multiple List<>?
- C# LINQ, Remove all elements that are equal
- Linq to XML: Get all nodes that contain certain children
- Only get filtered elements from class properties
- C# JSON.Net parse and get list of all elements matching a value using LINQ
- LINQ to XML: How to get all elements by value
More Query from same tag
- Convert Objects into Hierarchy based on Number Sequence
- C# How to compare 2 numbers that were pulled from a string
- Where clause bool fail
- "In clause" by LINQ to SQL
- List from aggregated duplicate objects where a string property concats the strings from the duplicate objects in C#
- LINQ list exclude item with latest datetime
- How do I convert this SQL query to LINQ to SQL
- Implementation of List<T> is losing the ordering on the original query
- How to calculate the sum of all values in a dictionary excluding the first item's value?
- Use the data context as a method argument in LINQPad
- every Parameter object property that is not null, to be added to expression predicate as a condition
- Grouping a list of objects by parent using linq to output child elements
- C# LINQ: What is the difference between a Pull model and a Push model?
- Am I at a dead end in my linq?
- Reusable linq select query in Entity Framework
- Using LINQ to select a byte array
- What does the error "Extension method must be static" mean?
- LINQ Query - exclude the values of one list from another list
- LINQ select query
- Select only first record within a time interval
- Enumerable.Zip to enforce same lengths
- LINQ query compary multiple with multiple
- Nested Func<T, object> in a Generic Extension Method
- Check if list of string contains object property value, and if it does remove it from the list of strings
- Queryable.Aggregate is not working with null values
- Add items to list from IEnumerable using LinQ
- How can I use ':' character in a name of XDocument element?
- Linq query filter with "contains" with list<T> multiple elements
- How to rewrite duplicate keys in dictionary?
- Template / generic way to use LINQ SQL?