现在有A,B两个String数组
A的值为{“a1”,“a5”}
B的值为{"a1","a2","a3","a4","a5","a6"}
有什么方法可以去掉B数组中 与A数组中相同的元素?
或者 合并两个数组去掉相同元素也行
A的值为{“a1”,“a5”}
B的值为{"a1","a2","a3","a4","a5","a6"}
有什么方法可以去掉B数组中 与A数组中相同的元素?
或者 合并两个数组去掉相同元素也行
解决方案 »
- 求一个奇怪的问题,高手来。。在线等
- .Net+Sql2005 实现图片批量上传
- 关于火车时刻查询表的设计问题
- IIS设置的奇怪问题?
- QQ空间自定义管理如何实现?(版式/布局,模块,风格,自定义装扮,一键装扮)
- 为什么我的cookie这几天用不了?!
- 添加数据库遇到的问题
- 高分求一活页夹式代码。谢谢!类似于http://www.1598.net/,点击某一类别,此类别背景变,下面的项也变。
- OleDbDataReader可不可以这样用取得两个表的字段~~
- ServiceProcess不能启动电脑上的服务
- 你们做导入导出的时候用的是office的com,还是openXML还是VSTO,各自的优缺点?
- for循环 输出日期
void Main()
{
string[] a={"a1","a5"};
string[] b={"a1","a2","a3","a4","a5","a6"};
b = b.Except(a).ToArray();
foreach (string s in b)
{
Console.WriteLine(s);
}}
//结果:
a2
a3
a4
a6
string[] arr2= new string[7] { "a","b","d","e","f","g","h"};
string[] temparr1= arr1.Except(arr2).ToArray();
string[] temparr2 = arr2.Except(arr1).ToArray();
int[] b = { 1, 4, 5, 7, 8, 9 };
List<int> la = new List<int>(a);
List<int> lb = new List<int>(b);
List<int> lc = new List<int>();
foreach (int i in la)
{
if (!lb.Contains(i))
{
lc.Add(i);
}
}
foreach (int i in lb)
{
if (!la.Contains(i))
{
lc.Add(i);
}
}
LINQ Intersect(交集),Except(差集).
int[] result= A.Except(B).ToArray();
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] A = new string[] { "a1", "a5" };
string[] B = new string[] { "a1", "a2", "a3", "a4", "a5", "a6" };
List<string> all = new List<string>();
for (int i = 0; i < A.Length; i++)
{
if (!all.Contains(A[i]))
all.Add(A[i]);
}
for (int j = 0; j < B.Length; j++)
{
if (!all.Contains(B[j]))
all.Add(B[j]);
}
all.Sort();
for (int i = 0; i < all.Count; i++)
{
Console.WriteLine(all[i]);
} Console.ReadLine();
}
}
}
for(i=0;i<6;i++) {for(j=0;j<2;j++) if(b[i]!=a[j])
{
c[k]=b[i];
k++;
}
}
return c[k];
看到楼主的题目,我就随手写下来了,本想用C#写写看的,可是觉得是C。呵呵,路过留下脚印。
String[] b = {"a1","a2","a3","a4","a5","a6","a1" }; b= b.Except(a).ToArray<String>();