c# - Get all unmatching elements between two large lists -


i have dictionary<string, foo> x amount of elements. dictionary key containing foo.id. have list<foo> newfoos, in case contains little less elements dictionary. do, have new list<foo> elements in newfoos not in dictionary.

i solved using:

var list = mydict.where(x => newfoos.all(y => y.id != x.key)).tolist(); 

but problem performance in case, must easier , faster way? , please not using except/intersect , override equals

    public class program {      public static dictionary<int, foo> mydict { get; set; } = new dictionary<int, foo>();      private static void main(string[] args) {         (int = 0; < 2000; i++) {             mydict.add(i, new foo() {id = i});         }          var newfoos = new list<foo>();         (int = 0; < 1500; i++) {             newfoos.add(new foo() { id = });         }          var list = mydict.where(x => newfoos.all(y => y.id != x.key)).tolist();     } }  public class foo  {      public int id { get; set; }      //more properties  } 

when using testcode above find not slow, principle same

var list = newfoos.where(x => !mydict.containskey(x.id)).tolist(); 

this should more efficient since checking if key in dictionary should faster looking item in list.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -