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");

Related Query

More Query from same tag