Remove and Display Duplicate Data from Array using Linq in C#.
Hide Duplicate Data.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Test_Application
{
public class Program
{
static void Main(string[] args)
{
int j = 1;
int[] a = { 3, 8, 5, 9, 2, 0, 2,1 };
var k = (from i in a orderby i descending select i).Distinct();
foreach (var s in k)
{
Console.WriteLine(s);
}
Console.ReadLine();
}
}
}
Output :- 9 8 5 3 2 1 0
Display Duplicate Data using LINQ From Array in C#.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Test_Application
{
public class Program
{
static void Main(string[] args)
{
int j = 1;
int[] a = { 3, 8, 5, 9, 2, 0, 2,9,1 };
var k = a.GroupBy(i => i).Where(g => g.Count() > 1).Select(g => g.Key);
foreach (int r in k)
{
Console.WriteLine(r);
}
Console.ReadLine();
}
}
}
Output :- 9 2.