如下:
数组A:
int[] A=new int[5];
A[0]=1;
A[1]=2;
A[2]=3;
A[3]=4;
A[4]=5;数组B:
int[] B=new int[3];
B[0]=1;
B[1]=3;
B[2]=4;得到新的数组C
C[0]=2;
C[1]=5;
数组A:
int[] A=new int[5];
A[0]=1;
A[1]=2;
A[2]=3;
A[3]=4;
A[4]=5;数组B:
int[] B=new int[3];
B[0]=1;
B[1]=3;
B[2]=4;得到新的数组C
C[0]=2;
C[1]=5;
解决方案 »
- 无法启动程序“http://localhost:1768/myweb/Default.aspx”
- asp.net 导入txt excel文件的速度问题
- c#操作cookie记录访问的历史记录
- gridview显示混乱了,请大家帮帮新手
- 如何在Gridview中做一个象Google一样的Paging?
- asp.net 2.0 有了dataSource
- 帮我解决几个问题,送50分
- 思归等高手入内,连接AS/400 db2 的问题,感谢大家指点迷津!!!!
- 知道HTM文件的物理路径,怎样在网站程序里调用显示
- 请问怎样才能实现在datagrid中的按钮事件?我想在按钮的单击事件中出现一个howModalDialog窗口。这样可以解决吗?
- asp.net 关于图片热点问题
- fckeditor在asp.net中怎么设置上传图片?现在点完上传图片没有反应?
for(i=n;i<A.length();i++)
{A[n]=A[n+1];}
A[i]=null;
for(i=n;i<A.length();i++)
{A[i]=A[i+1];}
A[i]=null;
string c="";
foreach(int a in A)
{
int flat = 0;
foreach(int b in B)
{
if(a==b)
{
flat = 1;
}
}
if(flat == 0)
{
c += a + ",";
}
}string[] C = c.Substring(0,c.Length-1).Split(',');//要int[] 的就转换下
//显示结果
foreach(string cc in C)
{
Response.Write(cc+"<br>");
}
using System.Collections.Generic;
using System.Collections;public class SubtrationArray<T>{
public T[] Subtration(T[] a,T[] b){
ArrayList al=new ArrayList();
foreach(object obj in a){
if(Array.BinarySearch(b,obj)<0){
al.Add(obj);
}
}
return (T[])al.ToArray(typeof(T));
}
}
public class MyClass
{
public static void Main()
{
try{
int[] A=new int[5]{1,2,3,4,5};
int[] B=new int[3]{1,3,4};
SubtrationArray<int> sa=new SubtrationArray<int>();
int[] c=sa.Subtration(A,B);
foreach(int i in c){
Console.WriteLine(i);
}
string[] AA=new string[]{"one","two","three"};
string[] BB=new string[]{"one","three"};
SubtrationArray<string> SS=new SubtrationArray<string>();
string[] CC=SS.Subtration(AA,BB);
foreach(string i in CC){
Console.WriteLine(i);
}
}
catch(Exception e){
Console.WriteLine(e.ToString());
}
finally{
Console.WriteLine("END");
Console.Read();
}
}
}
int[] A = new int[5];
A[0] = 1;
A[1] = 2;
A[2] = 3;
A[3] = 4;
A[4] = 5;
int[] B = new int[3];
B[0] = 1;
B[1] = 3;
B[2] = 4;
System.Collections.ArrayList a = new System.Collections.ArrayList(A.Length + B.Length);
foreach (int aa in A)
{
a.Add(aa);
}
foreach (int bb in B)
{
a.Add(bb);
}
for (int i = 0; i < a.Count; i++)
{
for (int j = i + 1; j < a.Count; j++)
{
if (i != a.Count - 1)
{
if (a[i].ToString() == a[j].ToString())
{
a.RemoveAt(i);
a.RemoveAt(j - 1);
i--;
}
}
}
}
int[] C=new int[a.Count];
for (int k = 0; k < a.Count; k++)
{
C[k] = Convert.ToInt32(a[k]);
Console.WriteLine(C[k]);
}
Console.ReadLine();
}