嗨,我无法使这段代码工作,因为它说"not all code paths return a value."我不确定这里有什么不起作用


using System;
namespace code1
{
class Program
{
static object main()
{
Console.WriteLine("What's your name?");
string input = Console.ReadLine();
Console.WriteLine($"Hello {input}!");
/* This part will tell the user their age in a string */
Console.WriteLine("How old are you?");
double age = Convert.ToInt32(Console.ReadLine());
Console.WriteLine($"You are {age} years old");
Console.WriteLine("Next Part....");
Console.WriteLine("Next.");

}
}

}

函数main的返回类型错误。它应该一无所获。

using System;
namespace code1
{
class Program
{
static void main()
{
Console.WriteLine("What's your name?");
string input = Console.ReadLine();
Console.WriteLine($"Hello {input}!");
/* This part will tell the user their age in a string */
Console.WriteLine("How old are you?");
double age = Convert.ToInt32(Console.ReadLine());
Console.WriteLine($"You are {age} years old");
Console.WriteLine("Next Part....");
Console.WriteLine("Next.");

}
}

}

编辑2:您还应该与数据类型保持一致。您将年龄定义为双倍,但将<strong]用户输入转换为Int32>使用Convert.ToDouble()将变量声明更改为int(或var以使用推理(。

方法的类型返回为Object,但不返回任何内容。静态对象main((

编辑:静态空隙主((

相关内容

最新更新