C#合并数组

C#合并数组
private static char[] Str =
{
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
};
private static char[] num =
{
'0','1','2','3','4','5','6','7','8','9'
};
private static char[] spCharacter =
{
'~','!','#','@','$','%','^','&','*','(',')','-','_','=','+','\\',' ','[',']','{','}','|',';',':','"',',',
'<','.','>','/','?','`'
};
public static string GenerateRandom(int Length, char[] sourceChar)
{
System.Text.StringBuilder newRandom
= new System.Text.StringBuilder(52);
Random rd
= new Random();
for (int i = 0; i < Length; i++)
{
newRandom.Append(sourceChar[rd.Next(sourceChar.Length)]);
}
return newRandom.ToString();
}
protected void btnGetStr_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtLength.Text))
{
int Indx = ddlStr.SelectedIndex;
char[] getStr = new char[] { };
switch (Indx)
{
case 1:
getStr
= num;
break;
case 2:
getStr
= Str;
break;
case 3:
getStr
= spCharacter;
break;
case 4:
getStr
= num.Union(Str).Distinct().ToArray();
break;
case 5:
getStr
= num.Union(spCharacter).Distinct().ToArray();
break;
case 6:
getStr
= Str.Union(spCharacter).Distinct().ToArray();
break;
case 7:
getStr
= Str.Union(spCharacter).Union(num).Distinct().ToArray();
break;
default:
break;
}
int Length = Convert.ToInt32(txtLength.Text.ToString());
this.txtStr.Text = GenerateRandom(Length, getStr);
//this.lblLen.Text = this.txtStr.Text.ToString().Length.ToString();
}
posted @ 2011-03-15 11:41  许明吉博客  阅读(965)  评论(0编辑  收藏  举报