我正在研究基本控制檯程序,如下所示。我很煩惱,後面這段代碼不起作用。什麼是檢查用戶輸入年齡並從Console.WriteLine重新運行代碼的最佳方法(「好吧,現在請輸入您的年齡。」);到if語句。與此根據條件重新運行代碼塊
int newAge = Convert.ToInt32(age);
int newAge = Int32.Parse(age);
:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Practice
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Thank you for participating in this survey. Please take a moment to fill out the required information.");
Console.WriteLine("Please Type Your Name");
string name = Console.ReadLine();
Console.WriteLine("Okay. Now please enter your age.");
string age = Console.ReadLine();
Console.WriteLine("Your information has been submitted.");
Console.WriteLine("Name: " + name + "\n" + "Age: " + age);
Console.ReadLine();
int newAge = Int32.Parse(age);
if (newAge => 18)
{
}
}
}
}
你似乎已經知道如何字符串轉換成int。請修正您的標題,以便正確反映您正在尋求幫助的內容。請參閱http://stackoverflow.com/help/how-to-ask – 2014-11-09 00:59:34