当前位置: 编程技术>.net/c#/asp.net
C#生成随机字符串的实例
来源: 互联网 发布时间:2014-10-17
本文导语: 代码如下:/// /// 生成随机字符串 /// private class RandomStringGenerator { static readonly Random r = new Random(); const string _chars = "0123456789"; public static string GetRandomString() { char[] buffer...
代码如下:
///
/// 生成随机字符串
///
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);
}
}