例:
string[] stringArray = { "aaa", "bbb", "aaa", "ccc", "bbb", "ddd", "ccc", "aaa", "bbb", "ddd" };
//List用於儲存從數組裡取出來的不相同的元素
List<string> listString = new List<string>();
foreach (string eachString in stringArray)
{
if (!listString.Contains(eachString))
listString.Add(eachString);
}
//最後從List裡取出各個字串進行操作
foreach (string eachString in listString)
{
Console.Write(eachString); //列印每個字串
}
=============================
例如string[]{"aaa","bbb","ccc","aaa","ccc"}
"aaa","ccc"有重複,如何去掉重複的字串,使之變成
string[]{"aaa","bbb","ccc"}
===========================
string[] stest = new string[]{"aaa","bbb","ccc","aaa","ccc"};
ArrayList list=new ArrayList();
for(int i = 0;i<stest.Length;i++)
{
bool IsExist = true ;
for(int j= 0;j<list.Count;j++)
{
if(list[j].ToString()==stest[i])
{
IsExist = false ;
break;
}
}
if(IsExist)
list.Add(stest[i]);
}
==========================
if(!list.Contains(stest[i]))
list.Add(stest[i]);
==============================
string[] a={"www","web","12","www","love","hehe","haha","hehe"}
ArrayList Arary=new ArrayList();
for(int i=0;i<a.Length,i++)
{
if(!Array.Contains(a[i]))
{
Array.Add(a[i]);
}
}
Array.ToArray(typeof(string))