Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么赢了';我的c#程序运行不正常?_C# - Fatal编程技术网

为什么赢了';我的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 {

我是一名刚开始学习c的大学生。我相信有一个简单的解决办法,但我已经搜索过了,我认为知道的还不够。 这是我的程序,注意我还没有完成一些功能

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
中)。首先,程序中没有要运行的内容,其次,您必须解决出现的错误,