If you are really concerned about performance, you should loop over the IEnumerable
and count it as you go. This avoids having to create a new collection altogether, and the intersection only has to be iterated once:
void Foobar(string[] arr, Dictionary)
{
var t = arr.Intersect(dic.Keys);
int count = 0;
foreach(var item in t)
{
count++;
..
}
var j = count;
}
But like someone else said: this smells of micro-optimization. If performance really matters in this situation, at least do performance profiling to find out which method is really the fastest for you.