score:5
Accepted answer
var result = a.keys.except(b);
score:1
dictionary<int, int> a = new dictionary<int, int>();
list<int> b = new list<int>();
// test filling...
random r = new random();
for (int i = 0; i < 1000000; i++)
{
int rnd = r.next(0, 2000000);
a[rnd] = rnd;
rnd = r.next(0, 2000000);
b.add(rnd);
}
// get time for linq except
stopwatch w = stopwatch.startnew();
var count = a.keys.except(b).count();
w.stop();
w.dump();
count.dump("count");
// get time for hashset
w = stopwatch.startnew();
hashset<int> ha = new hashset<int>(a.keys);
ha.exceptwith(b);
count = ha.count;
w.stop();
w.dump();
count.dump("count");
Source: stackoverflow.com
Related Query
- The fastest way to find dictionary keys that are not exist in another list
- How do I use Linq to find the elements of a list that are not present in another list?
- How to get the list elements that are not into another list C#
- Find all items that are not there in another list takes lot of time
- c#- select keys and values that does not exist in another dictionary
- LINQ Lambda - Find all ID's in one list that don't exist in another list
- Using LINQ to find all keys from one collection that are not in another?
- Calculating the sum of the values in a dictionary that exist in a generic list
- What is the fastest way to compare a value from a list to a specific sum from another list?
- Get items from input list that do not exist in the database using EF Core 2.1
- How do I get a list of integers that exist in one collection, but not in another of a different type using LINQ?
- How to count the occurence of each number in list A that is exist in list B and return zero if not existed?
- Speed Up Performance - LINQ to get items in one LIST, that are not in another List
- How to find keys in a Dict<int,List<Tuple<string,string>>> such that the list contains elements with given Item1 and Items
- Linq - Get all keys from dictionary where all values in the value list are equal to criteria
- Find all objects with list attribute element that exist in another list
- Compare two DataTables with several keys and select the rows that are not present in second table
- Find the number that don't exist in another array
- Get List of Records that do not exist in another list - Linq
- linq one liner to remove elements from IDictionary whose keys are not in another Dictionary
- Find and change the value of first element in list that meets a requirement, do something else if not found
- How to find the items that are repeated only once in the list using LINQ
- How can I take a list of dates, and remove any that are within 1 minute of another date in the list with LINQ?
- Use LINQ to get items in one List<>, that are not in another List<>
- LINQ query to find if items in a list are contained in another list
- LINQ - Find all items in one list that aren't in another list
- Find items from a list which exist in another list
- Using LINQ to Objects to find items in one collection that do not match another
- How to select values in list that are NOT IN a Table using EF Core?
- How do I combine the keys and values of a Dictionary into one List using LINQ?
More Query from same tag
- XDocument File Name
- Linq to XML - Create Xelement only IF something
- SQL wildcard _ in Linq
- Search list and order List by value max found c#
- Linq help - sub query gives null pointer exception
- Insert Records in multiple table which are dependent on primary / foreign key using Linq-to-SQL
- Linq: Add non-existing itemList to database by checking (not Id) but other 'multiple' properties
- Dynamic table names in Entity Framework linq
- 'orderby' in linq using a string array c#
- Use Linq query to compare date only with DateTime field
- how can i use datetime.addyyyx functions in a linq-to-entities query?
- ASP.NET How to retrieve a list of the empty labels on a page?
- C# Linq convert collection using groupby
- LINQ: latest sum of data within data range
- Multiple linq "from" and variables visibility
- Non-Specific Type in Expression.Lambda Generics
- returning data from both the tables link with foreign key without join operations. i want only single table data
- Best practice for translating Linq result to Dictionary
- How do we switch from Telerik Open Access to anything else?
- How to use linq with an aggregate , join and Group by
- What are the Java equivalents to Linq and Entity Framework
- C# Store A List As a Comma Separated String In String Type Variable With Number Of Occurrence Of Items In The List
- How to convert groupby query to linq and compute other thing while executing?
- T-SQL Query Performance Improvement
- How to filter a list based on another list using Linq?
- Failed to set Database initializer Entity Framework
- Where is the ToList() method? (IQueryable)
- LINQ to SQL dividing filters for better performance
- How to do a left outer join in Entity Framework without using the query syntax?
- How would you implement LINQ methods with SelectMany?