List<int> list1 = new int[] { 1, 1, 2, 3, 4, 5 }.ToList(); List<int> list2 = new int[] { 1, 1, 2 }.ToList(); var result = list1.Intersect(list2); foreach (int i in result) Console.WriteLine(i);
int[] arr = new int[] { 1, 1, 2 }; //Create a dictionary where the key is each int occurance //and the value is the number of int occurances. Dictionary<int, int> dict = arr.Distinct().ToDictionary(i => i, i => arr.Where(ii=>ii==i).Count()); //now do what you like with it.. //eg get me the value that occurs least often, //which I think is what you're after: int r=dict[dict.Values.Min()];
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)