C#生成随机字符串的实例
更新时间:2013年03月06日 11:23:42 作者:
本文介绍了“C#生成随机字符串的实例”,需要的朋友可以参考一下
复制代码 代码如下:
/// <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);
}
}
相关文章
c# DateTime常用操作实例(datetime计算时间差)
字符串操作DateTime操作,datetime计算时间差,取当前时间,更多方法看下面代码2013-12-12
最新评论