C# 生成随机的6位字母,包含大小写

今天自己做项目需要生成随机的6位字母,于是自己写了一个,下面代码是可以生成任意位数字母的。

string _zimu = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";//要随机的字母
Random _rand = new Random(); //随机类
string _result = "";
for(int i = 0;i<6;i++) //循环6次,生成6位数字,10位就循环10次
{
_result += _zimu[_rand.Next(52)]; //通过索引下标随机

}
Console.WriteLine(_result);//控制台输出
Console.ReadKey();

原文地址:https://www.cnblogs.com/zjbd/p/11433473.html