【发布时间】:2019-11-06 21:45:58
【问题描述】:
我的程序有一个奇怪的问题。我想打印出我的名字、姓氏和年龄,我觉得这里有一个我只是没有看到的简单解决方案。
这是我的代码:
string firstname; //the data type that is named and initialised
string lastname;
string userAge;
int age;
//takes user input
Console.Write("please enter your first name - ");
//stores user input
firstname = Console.ReadLine();
Console.Write("please enter your last name - ");
lastname = Console.ReadLine();
Console.Write("please enter your age - ");
userAge = Console.ReadLine();
//this is a bit of useless code I was playing around with earlier
//age = Console.Readline();
userAge = Convert.ToInt32(age);
//prints user input to screen the 0 is the position
Console.WriteLine("Your name is {0} {1}", firstname,lastname + "and your age is",age);
//pauses the program for 1000 mlseconds so you can see what the result is
Thread.Sleep(2000);
【问题讨论】:
-
你能解释一下它的哪一部分不起作用吗?你看到了什么?你能指望什么?这对于有经验的开发人员来说可能很明显,但在编写高质量问题时它们是重要的细节。
-
对不起 userAge = convvert.ToInt32(age);有一个错误说你不能简单地将类型 int 转换为字符串我想在屏幕上打印我的名字姓氏和年龄年龄部分不起作用,因为它不显示数字