c# 随机函数 太多了,懒的看,把最主要的问题表示出来。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //举一个例子给你List<string> student = new List<string>(); List<string> teacher = new List<string>(); List<string> result = new List<string>(); student.AddRange(new string[] { "A1","B1","C1","D1","E1"}); teacher.AddRange(new string[] { "A", "B", "C", "D", "E" }); for (int i = 0; i < student.Count; i++) { bool isFindSelt = false; if(teacher.Contains(student[i].Substring(0,1))) { teacher.Remove(student[i].Substring(0, 1)); isFindSelt = true; } Random rand = new Random(); int index = rand.Next(0, teacher.Count - 1); string s = teacher[index]; teacher.RemoveAt(index); if (isFindSelt) teacher.Add(student[i].Substring(0, 1)); result.Add(student[i] + "--" + s); } for (int i = 0; i < result.Count ; i++) { System.Windows.Forms.MessageBox.Show(result[i].ToString()); } 后台服务里使用GetForegroundWindow返回的都是0? 做了一个wcf的小例子,遇到一个奇怪的问题,传送大数据量总出错 C#数据连接的问题?? 初学者提若智问题! C#中利用栈求表达式的值 提问: 获取论坛和网站模板设计理念 在此论坛中能不能粘贴图片,我想把我的WEB界面显示出来讨论一下。 正则问题 能否将DataSet中的现存数据转换成Insert语句? 向各位高手请教下这个问题! 如何学习c#?
//举一个例子给你
List<string> student = new List<string>();
List<string> teacher = new List<string>();
List<string> result = new List<string>();
student.AddRange(new string[] { "A1","B1","C1","D1","E1"});
teacher.AddRange(new string[] { "A", "B", "C", "D", "E" });
for (int i = 0; i < student.Count; i++)
{
bool isFindSelt = false;
if(teacher.Contains(student[i].Substring(0,1)))
{
teacher.Remove(student[i].Substring(0, 1));
isFindSelt = true;
}
Random rand = new Random();
int index = rand.Next(0, teacher.Count - 1);
string s = teacher[index];
teacher.RemoveAt(index);
if (isFindSelt)
teacher.Add(student[i].Substring(0, 1));
result.Add(student[i] + "--" + s);
}
for (int i = 0; i < result.Count ; i++)
{
System.Windows.Forms.MessageBox.Show(result[i].ToString());
}