如何去除List集合中重复的元素

        // <summary>
        /// 去除List集合中的重复元素
        /// </summary>
        /// <param name="list">要去除重复元素的集合</param>
        /// <returns>返回处理后的集合</returns>
        public static List<TypeAndName> ItemFilter(List<TypeAndName> list)
        {
            List<TypeAndName> resultList = new List<TypeAndName>();
            for (int i = 0; i < list.Count; i++)
            {
                for (int j = i + 1; j < list.Count; j++)
                {
                    if (list[i].Name == list[j].Name && list[i].Name != "重复值")
                    {
                        list[j].Name = "重复值";
                    }
                }
            }
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].Name != "重复值")
                {
                    TypeAndName single = new TypeAndName();
                    single.Name = list[i].Name;
                    single.Type = list[i].Type;
                    resultList.Add(single);
                }
            }

            return resultList;
        }

如何去除List集合中重复的元素

上一篇:解决openfire中发送某些特殊字符会断开xmpp连接的问题


下一篇:第三章 沟通的技巧