ArrayList问题大家帮帮忙
我想删除ArrayList中的重复数据请问怎么办
------解决方案--------------------using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ArrayList list = new ArrayList();
list.Add(1);
list.Add(2);
list.Add(3);
list.Add(4);
list.Add(2);
list.Add(3);
PrintList(list);
RemoveDupItem(list);
PrintList(list);
}
private static void RemoveDupItem(ArrayList list)
{
int i = 0;
while (i < list.Count)
{
int j = i + 1;
while (j < list.Count)
{
if (list[i].Equals(list[j]))
{
list.RemoveAt(j);
}
else
{
j++;
}
}
i++;
}
}
static void PrintList(ArrayList list)
{
foreach (object var in list)
{
Console.WriteLine(var.ToString());
}
}
}
}