static void Main(string[] args)
{
int[] arr = { 1, 3, 3, 3, 3, 4, 5, 4, 5, 8, 9, 3 };
//不重复
var unique = arr.GroupBy(o => o).Where(g => g.Count() == 1)
.Select(g => g.ElementAt(0));
var uniqueList = arr.Distinct<int>().ToList();
foreach(var a in uniqueList)
{
Console.WriteLine(a);
}
Console.WriteLine("
");
foreach (var a in unique)
{
System.Diagnostics.Debug.WriteLine(a);
Console.WriteLine(a);
}
Console.ReadLine();
//重复元素
var duplicate = arr.GroupBy(o => o)
.Where(g => g.Count() > 1)
.Select(g => g.ElementAt(0));
foreach(var a in duplicate)
{
Console.WriteLine(a);
}
Console.ReadLine();