C# 生成随机数的代码片段

c#
2015-05-02 0 632
C# 生成随机数的代码片段

下面的c#代码片段显示产生随机数输出到控制台。
RandomNumber函数的第一个参数为生成的随机数的最小值。第二个参数是最大值+ 1。

using System;
  
class Program
{
   private Random random = new Random();
  
   private int RandomNumber (int min, int max)
   {
      return random.Next (min, max);
   }
  
   public static void Main(string[] args)
   {
      Program program = new Program();
      for (int i = 0; i <= 10; i++)
      {
         Console.WriteLine (program.RandomNumber(1, 100));
      }
  
      Console.ReadKey(); // wait so you have time to see the output
   }
}

遇见资源网 c# C# 生成随机数的代码片段 http://www.ox520.com/12402.html

上一篇: C#连接mysql类
常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务