using System;
using System.Globalization;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class Test
{
public static void Main()
{
int[] numbers = {1,2,2,3,3,4,4,5};
var allUniques = numbers.GroupBy(i => i)
.Where(group => !group.CountMoreThan(1))
.Select(group => group.Key).ToList();
foreach(int i in allUniques)
Console.WriteLine(i);
}
}
public static class Extensions
{
public static bool CountMoreThan<TSource>(this IEnumerable<TSource> source, int num)
{
if (source == null)
throw new ArgumentNullException("source");
if (num < 0)
throw new ArgumentException("num must be grater or equal 0", "num");
ICollection<TSource> collection = source as ICollection<TSource>;
if (collection != null)
{
return collection.Count > num;
}
ICollection collection2 = source as ICollection;
if (collection2 != null)
{
return collection2.Count > num;
}
int count = 0;
using (IEnumerator<TSource> enumerator = source.GetEnumerator())
{
while (++count <= num + 1)
if (!enumerator.MoveNext())
return false;
}
return true;
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uR2xvYmFsaXphdGlvbjsKdXNpbmcgU3lzdGVtLkxpbnE7CnVzaW5nIFN5c3RlbS5Db2xsZWN0aW9uczsKdXNpbmcgU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWM7CgpwdWJsaWMgY2xhc3MgVGVzdAp7CglwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCgl7CiAgICAgICAgaW50W10gbnVtYmVycyA9IHsxLDIsMiwzLDMsNCw0LDV9OwoJCXZhciBhbGxVbmlxdWVzID0gbnVtYmVycy5Hcm91cEJ5KGkgPT4gaSkKCQkgICAgLldoZXJlKGdyb3VwID0+ICFncm91cC5Db3VudE1vcmVUaGFuKDEpKQoJCSAgICAuU2VsZWN0KGdyb3VwID0+IGdyb3VwLktleSkuVG9MaXN0KCk7CiAgICAgICAgZm9yZWFjaChpbnQgaSBpbiBhbGxVbmlxdWVzKQogICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZShpKTsKCX0KfQoKcHVibGljIHN0YXRpYyBjbGFzcyBFeHRlbnNpb25zCnsKCXB1YmxpYyB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