How do I check if my array has repeated values inside it?
问题 So here is my array. double[] testArray = new double[10]; // will generate a random numbers from 1-20, too lazy to write the code I want to make a search loop to check if any values are being repeated. How do I do that? I would prefer not to use any special built-in methods since this is a small array. 回答1: You could do this with a little Linq: if (testArray.Length != testArray.Distinct().Count()) { Console.WriteLine("Contains duplicates"); } The Distinct extension method removes any