日期:2014-05-17  浏览次数:20508 次

中秋快乐!同一个字符数组中,怎么合并两个值相同的元素?
比如这样的:
C# code

string[] arr=new string[]{"a","b","c","a","d","a","b"};
string[] arrResult=new string[]{"a","b","c","d"};


如何把数组arr中重复的元素a和b去掉,最终把它变成arrResult样的?
谢谢!

------解决方案--------------------
string[] arr = new string[]{"aa","bb","bb,"cc"};
List<string> list = new List<string>();
foreach(string s in arr)
{
if(list.Contains(s)) continue;
list.Add(s);
}

得到list 就是结果
------解决方案--------------------
C# code
string[] arrResult = arr.Distinct().ToArray();

------解决方案--------------------
探讨
C# code
string[] arrResult = arr.Distinct().ToArray();