CSharp examples for Collection:List
Finding the overlap in two lists
using System;// ww w . java 2 s. c om using System.Collections.Generic; class Program { static void Main(string[] args) { List<string> presidentialCandidates = new List<string> { "B", "C", "D", "T", "E", "X" }; List<string> senators = new List<string> { "A", "QQ", "B", "T", "E", "N" }; // Following set hasn't yet weeded out non-Senators ... HashSet<string> senatorsRunning = new HashSet<string>(presidentialCandidates); senatorsRunning.IntersectWith(senators); foreach (string senator in senatorsRunning) { Console.WriteLine(senator); } } }