Dictionary<object, int> dic = new Dictionary<object, int>();
ArrayList list = new ArrayList();
string[] s = { "AA", "AB", "AD", "AA ", "DD" };
for (int i = 0; i < s.Length; i++)
{
list.Add(s[i].Trim());
}
int num = 1;
for (int j = 0; j < list.Count; )
{
object obj = list[j];
dic.Add(obj, 1);
list.Remove(obj);
while (list.Contains(obj))
{
num = num + 1;
dic.Remove(obj);
dic.Add(obj, num);
list.Remove(obj);
用LINQ来做
String[] f = { "科技", " 科技", "信息", "外包", " 科技", "酒店", "酒店" };
var q = (from s in f
select s.Trim()).Distinct<string>();
f = q.ToArray();
foreach (string s in f)
{
System.Diagnostics.Debug.WriteLine(s);
}