码迷,mamicode.com
首页 > 其他好文 > 详细

产生随机数、三元表达式

时间:2017-04-01 20:37:29      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:oid   技术   产生   static   pac   code   string   one   ons   

1.通过Random类来产生随机数   Next(1, 10);取值范围是1~9

技术分享
using System;
namespace shuzu
{    
 static class aclass { 
        static void Main(string[] args)
     {
         Random r = new Random();//创建随机数对象
            while(true){
                int t = r.Next(1, 10);//通过对象方法来产生随机数
             Console.WriteLine(t);
             Console.ReadKey();
            }
           
        }
    }
}
View Code

 2.三元表达式    

技术分享
using System;
namespace shuzu
{    
 static class aclass { 
        static void Main(string[] args)
     {
            int a,b,c;
            a=10;
            b=11;
            c=a>b?a:b;//满足条件a>b结果c=a;否则c=b;
          
             Console.WriteLine(c);
             Console.ReadKey();
            }
           
        }
    }
View Code

 

产生随机数、三元表达式

标签:oid   技术   产生   static   pac   code   string   one   ons   

原文地址:http://www.cnblogs.com/syzly/p/6657343.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!