Taking advantage of the fact that a HashSet has no duplicate entries: you can sum the entries they share by taking the difference of the total count of items in two Hashsets and subtract the number of items in their 'Union:
HashSet<string> hs1 = new HashSet<string>
{
"m0","m1","m2","m7"
};
HashSet<string> hs2 = new HashSet<string>
{
"m0","m2","m7"
};
private int GetSharedMovieCount(HashSet<string> h1, HashSet<string> h2)
{
return h1.Count + h2.Count - (h1.Union(h2).Count());
}
Dictionary<string, HashSet<string>> movies = new Dictionary<string, HashSet<string>>
{
{"movie1", hs1},
{"movie2", hs2}
};
int cnt = GetSharedMovieCount(movies["movie1"], movies["movie2"]);