代碼如下:
/// <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);
}
}