using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
void Page_Load() void Page_Load(object sender, EventArgs e)
{
string str1 = "010&011&012&112&151";
string str2 = "010&011&012&112&151";
string[] user1 = str1.Split( '&');
string[] user2 = str2.Split( '&');
string[] user3 = MergeArray(user1, user2);
for (int i = 0; i < user3.Length; i++)
{
Response.Write(user3[i]+ "<br>");
}
}
static string [] MergeArray() static string [] MergeArray( string [] a, string [] b)
{
ArrayList student = new ArrayList();
foreach ( string s1 in a)
{
student.Add(s1);
}
foreach ( string s2 in b)
{
bool flag = true;
for (int i = 0; i < a.Length; i++)
{
if(a[i]==s2)
{
flag = false;
break;
}
}
if (flag)
{
student.Add(s2);
}
}
string[] c1= ( string[])student.ToArray(typeof( string));
return c1;
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
void Page_Load() void Page_Load(object sender, EventArgs e)
{
string str1 = "010&011&012&112&151";
string str2 = "010&011&012&112&151";
string[] user1 = str1.Split( '&');
string[] user2 = str2.Split( '&');
string[] user3 = MergeArray(user1, user2);
for (int i = 0; i < user3.Length; i++)
{
Response.Write(user3[i]+ "<br>");
}
}
static string [] MergeArray() static string [] MergeArray( string [] a, string [] b)
{
ArrayList student = new ArrayList();
foreach ( string s1 in a)
{
student.Add(s1);
}
foreach ( string s2 in b)
{
bool flag = true;
for (int i = 0; i < a.Length; i++)
{
if(a[i]==s2)
{
flag = false;
break;
}
}
if (flag)
{
student.Add(s2);
}
}
string[] c1= ( string[])student.ToArray(typeof( string));
return c1;
}
}
转载于:https://blog.51cto.com/824876/181795