为什么我的c#程序不能运行?

本文关键字:运行 不能 程序 我的 为什么 | 更新日期: 2023-09-27 18:07:04

我是一名刚开始学习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()
             {
             }
        }
    }
}

在Visual Studio中,我有两个错误:一个说'}'预计在Main之后;在最后出现了一个错误:"type or namespace definition error"

为什么我的c#程序不能运行?

在方法内部声明方法。这是错误的。

改变:

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()
    {
    }
}