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);
}
}
相關(guān)文章
c# 如何實現(xiàn)獲取二維數(shù)組的列數(shù)
這篇文章主要介紹了c# 實現(xiàn)獲取二維數(shù)組的列數(shù)操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-04-04C#中的Linq Intersect與Except方法使用實例
這篇文章主要介紹了C#中的Linq Intersect與Except方法使用實例,本文直接給出示例代碼,需要的朋友可以參考下2015-06-06C# Dynamic關(guān)鍵字之:調(diào)用屬性、方法、字段的實現(xiàn)方法
本篇文章是對C#中調(diào)用屬性、方法、字段的實現(xiàn)方法進行了詳細的分析介紹,需要的朋友參考下2013-05-05