C#语言,现在要生成10位随机码,包含数字,大小写字母,如何生成,谢谢各位大神

2025-03-07 08:33:34
推荐回答(1个)
回答1:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RandomStringDemo
{
class Program
{
static void Main(string[] args)
{
string chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

Random randrom = new Random((int)DateTime.Now.Ticks);

string str = "";
for (int i = 0; i < 10; i++) {
str += chars[randrom.Next(chars.Length)];
}

Console.WriteLine(str);
Console.Read();
}
}
}

可以吗?有疑问可以追问哦。