Linq List<string> union

c#, linq

Solution

var items = list1.Intersect(list2);

See also:

- `Intersect`

- Much recommended: 101 LINQ Samples

Problem

How can I use Linq to find common items between 2 generic lists of type string. For example, say I have the following code, I would like to get a List < string> which would contain item2 and item3: ``` List<string> List1 = new List<string>(); List<string> List2 = new List<string>(); List1.Add("item1"); List1.Add("item2"); List1.Add("item3"); List2.Add("item2"); List2.Add("item3"); List2.Add("item4"); ```

Original source