I want to remove all the duplicates in this array and I can't quite make it work. When all the duplicates are removed, I want to create a new array without the removed numbers. Here's my code:
static void Main(string[] args)
{
int[] s = { 11, 11, 12, 12, 13, 13, 14, 15, 16 };
int[] q = s.Distinct().ToArray();
Console.WriteLine(q.ToString());
Console.ReadLine();
}
This prints the array {11, 12, 13, 14, 15, 16}; but I wanted it to print the array {14, 15, 16}.
q.ToString()is pointless if you don't want to know the full name of the array-type. Usestring.Join(",", q)instead.new [] { 11, 11 }.Distinct().ToArray()returnsint[]{ 11 }. It looks like you're expecting it to return an empty set.