fork(4) download
  1. using System;
  2. using System.Globalization;
  3. using System.Linq;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. int[] numbers = {1,2,2,3,3,4,4,5};
  12. var allUniques = numbers.GroupBy(i => i)
  13. .Where(group => !group.CountMoreThan(1))
  14. .Select(group => group.Key).ToList();
  15. foreach(int i in allUniques)
  16. Console.WriteLine(i);
  17. }
  18. }
  19.  
  20. public static class Extensions
  21. {
  22. public static bool CountMoreThan<TSource>(this IEnumerable<TSource> source, int num)
  23. {
  24. if (source == null)
  25. throw new ArgumentNullException("source");
  26. if (num < 0)
  27. throw new ArgumentException("num must be grater or equal 0", "num");
  28.  
  29. ICollection<TSource> collection = source as ICollection<TSource>;
  30. if (collection != null)
  31. {
  32. return collection.Count > num;
  33. }
  34. ICollection collection2 = source as ICollection;
  35. if (collection2 != null)
  36. {
  37. return collection2.Count > num;
  38. }
  39.  
  40. int count = 0;
  41. using (IEnumerator<TSource> enumerator = source.GetEnumerator())
  42. {
  43. while (++count <= num + 1)
  44. if (!enumerator.MoveNext())
  45. return false;
  46. }
  47. return true;
  48. }
  49. }
  50.  
Success #stdin #stdout 0.05s 34184KB
stdin
Standard input is empty
stdout
1
5