实现代码如下:

/// <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#生成随机字符串的实例】的全部内容了,欢迎留言评论进行交流!

赞(0) 踩(0)

与本文相关的软件

发表我的评论

最新评论

  1. 暂无评论