c# - Remove duplicates from array and create a new array -


I want to remove all duplicates in this array and I can not do a lot of work when all duplicates are removed I want to create a new array without extracted numbers. My code is:

  Fixed zero main (string [] arg) {int [] s = {11, 11, 12, 12, 13, 13, 14, 15, 16}; Int [] q = s.Distinct (). ToArray (); Console.WriteLine (q.ToString ()); Console.ReadLine (); }  

This array prints {11, 12, 13, 14, 15, 16}; But I wanted to print it {14, 15, 16} array.

Use:

  int [] s = {11, 11, 12, 12, 13, 13, 14, 15, 16}; Var NotDuplicateItems = s.GroupBy (r = & gt; r). Where (grp = & gt; grp.Count () == 1) .Select (r = & gt; r.Key). ToArray ();  

The above items will give you that are not duplicate in array s


Comments