10.接收用户输入

Console.ReadLine();   //用来接收用户在控制台的输入.
必须使用string类型的变量来接收.Console.ReadLine();的值.

练习:
1.问别人喜欢吃什么水果,假如用户输入"苹果"则显示哈哈,这么巧,我也喜欢苹果;

   
  1. namespace _10.接收用户输入_01
  2. {
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7. Console.WriteLine("请问你喜欢吃什么水果?");
  8. string fruits = Console.ReadLine();
  9. if (fruits == "苹果")
  10. {
  11. Console.WriteLine("哈哈我也喜欢吃{0}",fruits);
  12. }
  13. Console.ReadKey();
  14. }
  15. }
  16. }

2.请用户输入年龄,性别,当用户按下某个按键后,在屏幕上显示:您好:xxx您的年龄是xx.

   
  1. namespace _10.接收用户输入02
  2. {
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7. Console.WriteLine("请输入您的姓名:");
  8. string name = Console.ReadLine();
  9. Console.WriteLine("请输入您的年龄:");
  10. int age;
  11. try
  12. {
  13. age = Convert.ToInt32(Console.ReadLine());
  14. Console.WriteLine(name + ":您好,您的年龄是:" + age);
  15. }
  16. catch
  17. {
  18. Console.WriteLine("年龄输入不正确.");
  19. }
  20. Console.ReadKey();
  21. }
  22. }
  23. }





转载于:https://www.cnblogs.com/HelloZyjS/p/5995810.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值