1 #region 生成随机字符 2 /// <summary> 3 /// 生成随机字符 4 /// </summary> 5 /// <param name="lens">随机字符长度</param> 6 /// <returns>随机字符</returns> 7 private static string RandomString(int lens) 8 { 9 char[] CharArray = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', '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', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; 10 int clens = CharArray.Length; 11 string sCode = ""; 12 Random random = new Random(); 13 for (int i = 0; i < lens; i++) 14 { 15 sCode += CharArray[random.Next(clens)]; 16 } 17 return sCode; 18 } 19 #endregion