score:106
Accepted answer
sounds like you just want:
bool hassameelements = lista.intersect(listb).any();
edit: as noted in comments, intersect
uses lazy evaluation. it defers all execution until the first element is read from the result; at that point it will load all of listb
into a set, and then stream lista
until it finds a result to yield. at that point, any()
will return true
and so no more work will be done. see my edulinq post on intersect
for more information.
Source: stackoverflow.com
Related Query
- Check for any element that exists in two collections
- Fastest way to check whether a single element in common exists between two enumerables
- Dynamic "Not" by parameter in LINQ (Or any other code for that matter)
- Check if list contains element that contains a string and get that element
- C# Linq to XML check if element exists
- What is the best way to check two List<T> lists for equality in C#
- Any Intersection in Two Collections
- C# check an element exists while using LINQ to XML
- Best way to check if value exists for a key in ILookup<string, string> using linq
- Using linq to determine if any element is ListA exists in ListB?
- Search query using .Contains() for parameters that combine two columns
- Determine if two collections share at least one element
- Is there a way to speed up this code that finds data changes in two XML files?
- linq - how do you do a query for items in one query source that are not in another one?
- Is there any open source software for converting SQL statements to LINQ?
- Union two collections but only for objects with a matching id
- How to check for existence of an element with XElement?
- Data template for two enumerables that are grouped together
- Is there a faster way to check for an XML Element in LINQ to XML?
- LINQ for removing elements that are started with other element from list
- How to do a custom compare for every item in a intersect of two collections
- Need a LINQ code example to link two tables that have no foreign key
- Is there a faster way to check for an XML Element in LINQ to XML, and parse a bool?
- Check if any XML nodes exists with Specific Attribute using LINQ C#
- Does a code that combines single() with yield make any sense?
- LINQ to SQL: How to check if any item in one entity collection exists in another entity collection?
- Is there any preexisting extension for enumerable that makes it NullReferenceException safe?
- EntityFramework Any generates two EXISTS sql statements
- Joining data that exists in two tables and aggregating non joined data
- Select first element that has certain property if there are any duplicates otherwise select first element
More Query from same tag
- "Expression type 'NhDistinctExpression' is not supported by this SelectClauseVisitor." - with Query Syntax
- Expression<Func<TEntity, int, bool> set the int value
- Calling sql-specific operator/function (Full Text search) while still using ORM
- Linq with critera for nested list
- Windows Phone LocalDB Method has no supported translation to SQL
- Error using a subset of fields in Entity Framework
- querying a list - returns only one value
- IQueryable: Project columns by their names in linq dynamically at runtime
- Grouped Counts With linq
- How to access grouped values returned by a linq query
- How to order a list by type?
- Linq cannot filter elements in loop
- Linq to Sql query with multiple aggregations
- How to AND predicates in the WHERE clause in a LINQ to RavenDB query
- How to use Expression in Expression for single element
- Apply filters only if parameters has values in linq
- Lazy combinations
- Pure Speed for Lookup Single Value Type c#?
- Can't add sub-entities in Linq2Sql
- Turning SQL into LINQ Query C# mvc
- What is the fastest way of deleting files in a directory? (Except specific file extension)
- Is Linq and foreach in one statement preferable to 2 separate explicit statements?
- Outer join with linq query in EF Core 3 not working
- creating same type of objects based on a condition from an existing object ; C# LINQ
- checking value in datatable
- LINQPAD - PredicateBuilder throwing error
- How to get a column which type is float using linq to entities
- Query a JSON using LINQ
- Linq filter using a List
- Check if results from LINQ query contains a value