Duplicate Records in ArrayList

Posted by Murugavelmsc under C# on 2/9/2013 | Points: 10 | Views : 3736 | Status : [Member] | Replies : 5
Hi,

How to find duplicate records in arraylist?

Thanks,
Murugavel S

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/



Responses

Posted by: Satyapriyanayak on: 2/9/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
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);
}


}
}
}


Thanks
If this post helps you mark it as answer

If this post helps you mark it as answer
Thanks

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kundnani.Rt on: 2/12/2013 [Member] Starter | Points: 25

Up
0
Down
Its a perfect solution to the requirement !!!

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Saranpselvam on: 2/12/2013 [Member] Starter | Points: 25

Up
0
Down
ArrayList Items=new ArrayList();
ArrayList duplicateItems=new ArrayList();
Items.Add("1000");
Items.Add("1000");
Items.Add("1000");
Items.Add("3000");
Items.Add("5000");
Items.Add("2000");
Items.Add("4000");
Items.Add("6000");
Items.Add("5000");
Items.Add("6000");

foreach (var getitemname in Items)
{
if (duplicateItems.Contains(getitemname))
{
Response.Write(getitemname + "is a duplicate Item <br>");
}
else
{
duplicateItems.Add(getitemname);
}
}

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 2/12/2013 [Member] Silver | Points: 25

Up
0
Down
use arraylist.contains() function....

Regards,
Singaravel M

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kundan64 on: 2/13/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Murugavel,
Check the above link: http://forums.asp.net/t/1481176.aspx/1

Thanks.

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response