C# 移除数组中重复数据

先引用:using System.Linq;

   #region 移除数组中重复数据
        ///


        /// 移除数组中重复数据
        ///

        /// 需要除重的数组
        /// 不重复数组
        public static string[] DelRepeatData(string[] array)
        {
            return array.GroupBy(p => p).Select(p => p.Key).ToArray();
        }
 
        #endregion
 

list去除重复

string[] stringArray = { "aaa", "bbb", "aaa", "ccc", "bbb", "ddd", "ccc", "aaa", "bbb", "ddd" }; 
//List用于存储从数组里取出来的不相同的元素 
List listString = new List(); 
foreach (string eachString in stringArray) 

if (!listString.Contains(eachString)) 
listString.Add(eachString); 

你可能感兴趣的:(C# 移除数组中重复数据)