为什么赢了';我的c#程序运行不正常?
我是一名刚开始学习c的大学生。我相信有一个简单的解决办法,但我已经搜索过了,我认为知道的还不够。 这是我的程序,注意我还没有完成一些功能为什么赢了';我的c#程序运行不正常?,c#,C#,我是一名刚开始学习c的大学生。我相信有一个简单的解决办法,但我已经搜索过了,我认为知道的还不够。 这是我的程序,注意我还没有完成一些功能 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
public void welcome()
{
Console.WriteLine("Fuel Consumption Calculator "+"r/n"+"Are you using Metric 1 or Imperial 2 ?");
}
public void check()
{
string choice;
choice = Console.ReadLine();
if (choice == "1")
{
calcmetric();
}
else
{
calcimperial();
}
}
public void calcmetric()
{
}
public void calcimperial()
{
}
}
}
}
在VisualStudio中,我有两个错误:一个错误是在
Main
之后加上“}”;最后还有一个错误,说“类型或名称空间定义错误”。您在方法中声明方法。这是错误的
更改它:
class Program
{
static void Main(string[] args)
{
//call other methods here
welcome();
check();
//....
}
public static void welcome()
{
Console.WriteLine("Fuel Consumption Calculator "+"r/n"+"Are you using Metric 1 or Imperial 2 ?");
}
public static void check()
{
string choice;
choice = Console.ReadLine();
if (choice == "1")
{
calcmetric();
}
else
{
calcimperial();
}
}
public static void calcmetric()
{
}
public static void calcimperial()
{
}
}
您不能在方法中声明方法(即
check
在Main
中)。首先,程序中没有要运行的内容,其次,您必须解决出现的错误,