三元表达式:bool result=5>3? true:false;
Console.WriteLine("输入姓名:");
string name = Console.ReadLine();
if (name == "高山")
{
Console.WriteLine("没头发");
}
else
{
Console.WriteLine("有头发");
}
Console.ReadKey();
//三元表达式,只需一行就能解决
string temp=name == "高山" ? "没头发" : "有头发";
Console.WriteLine(temp);
Console.ReadKey();
随机数:Random r = new Random();
int number = r.Next(1,11); 从1到10
//随机数
Console.WriteLine("显示随机数");
while (true)
{
Random r = new Random();
int num = r.Next(0, 10);
Console.WriteLine(num);
Console.ReadKey();
}
Console.WriteLine("请输入人名:");
string name = Console.ReadLine();
Random r = new Random();
int number = r.Next(1, 3);
string temp = "";
if (number == 1)
{
temp = "拉皮条的";
}
else
{
temp = "老鸨";
}
Console.WriteLine("高山上辈子是{0}",temp);
Console.ReadKey();