score:-1
the count()
method takes a predicate, so you would do something like this:
if(myobjectlist.count(x => x.order == 1) >= 2)
{
// do something
}
score:1
not a pure linq-to-objects-solution, but how about:
var orderslist = new list<order>(myobjectlist.select(obj => obj.order);
bool allunique = orderslist.count == new hashset<order>(orderslist).count;
one would have to test performance of all the approaches presented here. i'd be careful, otherwise you end up quickly with some slow o(n²) look-ups.
score:1
what about distinct
?
bool allunique = orderslist.count == orderslist.select(o => o.order).distinct().count()
score:2
bool hasduplicates = myobjectlist.count >
new hashset<int>(myobjectlist.select(x => x.order)).count;
score:11
Source: stackoverflow.com
Related Query
- Determine whether two or more objects in a list are equal according to some property
- Find matching IDs between two different List Objects only when all IDs or more are present?
- LINQ: check whether two list are the same
- Check whether two comma separated strings are equal (for Content set)
- Test whether the elements in two ranges are equal in C# using a lambda and LINQ
- How to verify whether all dictionary KVP are included in some of other dictionary within list
- How to check if properties of two objects are equal
- Checking if two lists of objects are equal
- Compare two list of objects and select common and difference records based some property
- Add list of items to another object as a list where two values are equal
- Check if two lists are equal
- Linq query between two list objects
- Check if all values are equal in a list
- Merge two Lists in C# and merge objects with the same id into one list item
- The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects mvc 2
- Are there some disadvantages in using "a lot" of LINQ to Objects statements?
- How to convert list of objects with two fields to array with one of them using LINQ
- Removing a single item from an enumerable source when the items are equal
- Compare id's of objects in two lists and get the list of objects that includes objects with ids occurring in both of them
- How to identify if two List<string> are equal regardless of the order?
- Using LINQ to get the difference between two list of objects based only on a single object property
- Copy a list of objects to another typed list in one line of code
- Is there a Linq operation to determine whether there are items in a collection who have the same values for a pair of properties?
- Check if nullable boolean has value and if all are equal from list
- C# - Getting flat many-to-many List of Objects into List of distinct combinations of two Lists of objects
- Exclude list of complex objects from IQueryable by two properties
- Checking If Intervals Are of Equal Length in a List
- LINQ - EF Core - Return object that contains two objects (referenced by property) in nested list
- Cannot get more than one result when using System.Linq.Dynamic.Core to query a list of objects that have a member dictionary
- Check all properties in list of objects is equal
More Query from same tag
- Compare String with split in contains - LINQ
- LinqToDB Exception cannot be converted to SQL
- How to join table in LINQ and return list in MVC
- Is it possible to create a correlated subquery in LINQ?
- Does First() in LINQ cause eager or lazy loading?
- Dynamic Linq on Dapper dynamic collections - possible?
- linq order by 2 parameters
- What's the best way to get a single random element from a List<>?
- Which query expression would be equivalent to the following LINQ query?
- LINQ to SQL ,Join tables to get distinct result?
- Extension method to exclude records whose id exists anywhere in another field
- A LINQ question: map query expression to c# code
- How to select from list filtering through IN
- Simple Linq expression won't compile
- Specification inside LINQ with EF 4.3
- LINQ list to sentence format (insert commas & "and")
- c# Linq filter out records from a list within a dictionary
- List View Sliding Window
- Foreach with where clause when reading from a Sharepoint List
- How can one "scan" a lambda expression in C#?
- Entity Framework String Condition At List That Linked With ForeignKey
- telerik expression editor - change return type
- Aggregate a Dataset
- Dynamic columns report by using MVC
- Get object from mongodb c#
- Test if an IEnumerable<T> contains 1 element without counting or using Single
- Linq joined entity is null
- Casting linq query result to enum
- Getting a list of conversations with Entity Framework and linq
- Ternary execution of functions