剔除数组中重复的数据(C#)

SortedDictionary 命名空间using System.Collections.Generic; 对象的详细介绍:因为不是新东西。所以有很多人已经介绍过了。:http://kb.cnblogs.com/a/1741980/这里有详细。

 

代码。

                   string[] arr = new string[] { "12345678", "12345678", "123456789" };
                    //初始化Dictionary对象
                    SortedDictionary<string, int> freq = new SortedDictionary<string, int>();

                    foreach (string dicstr in arr)
                    {
                        if (!string.IsNullOrEmpty(dicstr.Trim()))
                        {
                            if (freq.ContainsKey(dicstr.Trim()))
                            {
                                freq[dicstr.Trim()]++;
                            }
                            else
                            {
                                freq.Add(dicstr.Trim(), 1);
                            }
                        }
                    }

 

结果:

 

posted on 2010-06-22 11:02  邹泽栋  阅读(506)  评论(0编辑  收藏  举报

导航