该程序将给我错误消息:
使用未分配的变量 yourName 和使用未分配的变量 yourIsp。
如果我取出 for 循环,它将运行。我试图向用户询问姓名和 isp 至少 4 次,并使用字符串操作从名字和姓氏创建电子邮件地址。
static void Main(string[] args)
{
string yourName; string yourIsp;
Console.WriteLine("Enter your full name:");
for (int i = 0; i < 4; i++)
yourName = Console.ReadLine();
Console.WriteLine("Enter your ISP:");
for (int j = 0; j < 4; j++)
yourIsp = Console.ReadLine();
char[] separator = {' '};
string[] yourWords;
yourWords = yourName.Split(separator);
string yourFirstName = yourWords[0];
string yourLastName = yourWords[1];
string yourEmailAddress = yourFirstName + yourLastName + "@" + yourIsp;
yourEmailAddress = yourEmailAddress.ToLower();
Console.WriteLine("Hello {0}, your email address is {1}", yourName, yourEmailAddress);
}