Find duplicate records in arraylist

Satyapriyanayak
Posted by Satyapriyanayak under C# category on | Points: 40 | Views : 1811
We will know how to Find duplicate records in arraylist. 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace Duplicate_Records_in_ArrayList
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
var list = new ArrayList { "Raj", "Raj", "Ravi", "Rahul"};
var dublicate =
(from string item in list select item).GroupBy(s => s).Select(
group => new { Word = group.Key, Count = group.Count() }).Where(x => x.Count >= 2);

foreach (var duplicate in dublicate)
{
MessageBox.Show("Duplicate records are:" + duplicate.Word);
}

}
}
}

Comments or Responses

Login to post response