C#生成随机字符串的实例
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下://////生成随机字符串///privateclassRandomStringGenerator{staticreado...
复制代码 代码如下:
/// <summary>
/// 生成随机字符串
/// </summary>
private class RandomStringGenerator
{
static readonly Random r = new Random();
const string _chars = "0123456789";
public static string GetRandomString()
{
char[] buffer = new char[5];
for (int i = 0; i < 5; i++)
{
buffer[i] = _chars[r.Next(_chars.Length)];
}
return new string(buffer);
}
}