太多了,懒的看,把最主要的问题表示出来。

解决方案 »

  1.   


    //举一个例子给你
    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());
                }