/两个(list)集合{"a","b","b","d","e"}和{"d","e","f","g","h"},把这两个集合取出重复项合并成一个。
static void Main(string[] args)
{
//两个(list)集合{"a","b","b","d","e"}和{"d","e","f","g","h"},把这两个集合取出重复项合并成一个。
List<string> listOne = new List<string>() { "a", "b", "b", "d", "e" };
List<string> listTwo = new List<string>() { "d", "e", "f", "g", "h" };
for(int i= 0; i < listTwo.Count; i++)
{
if (!listOne.Contains(listTwo[i]))
{
listOne.Add(listTwo[i]);//不包含该元素,就把该元素扔进来
}
}
for(int i = 0; i < listOne.Count; i++)
{
Console.WriteLine(listOne[i]);
}
Console.ReadKey();
//Console.WriteLine("可以不");r5
//Console.ReadKey();
}