【问题标题】:Console.WriteLine not printing out [closed]Console.WriteLine 没有打印出来[关闭]
【发布时间】:2018-09-15 16:14:34
【问题描述】:

我有一个课程InsuranceInsuranceTest,这些课程是一个更大的项目的一部分,入口点static void main(string[] args)。它拒绝执行这个入口点并且不打印出我的结果。

保险类别

namespace IT
{

    class Insurance
    {

        int cust;

        string agent;

        string state;

        public Insurance(int cust, string agent, string state)
        {
            this.cust = cust;
            this.agent = agent;
            this.state = state;
        }
        public Insurance(int cust, string agent)
            : this(cust, agent, "")
        {

        }
        public int Cust
        {
            get { return cust; }
            set { cust = value; }
        }

        public string Agent
        {
            get { return agent; }
            set { agent = value; }
        }
        public string State
        {
            get { return state; }
            set { state = value; }
        }
        public static void main(string[] args)
        {
            Employee e1 = new Employee("Sugar", "Insurance Ave", 6534);


            e1.Name = "Sugar";

            e1.Address = "Insurance Ave";
            e1.Id = 6534;
            Console.WriteLine(e1.Name);
            Console.WriteLine(e1.Address);
            Console.WriteLine(e1.Id);
        }

    }

}

保险测试类

namespace IT
{
    class InsuranceTest
    {
         static void main(string[] args)
        {



            Insurance i1 = new Insurance(7, "Agent Store", "PA");

            i1.Customers = 7;

            i1.Agent = "Agent Store";
            i1.State = "PA";
            Console.WriteLine("Total Customers" + i1.Cust);
            Console.WriteLine(i1.Agent);
            Console.WriteLine(i1.State);

        }

    }
}

注意:InsuranceTest 不是从入口点执行的。这些是许多类的类,当我在 Visual Studio 中转到项目的属性并尝试选择和启动对象时。 InsuranceTest 甚至没有出现。

【问题讨论】:

  • 方法区分大小写,你的主要方法是小写。

标签: c# console.writeline


【解决方案1】:

C# 方法名称区分大小写。 Main 应大写:

static void Main(string[] args)
{
    // Here ^

【讨论】:

    【解决方案2】:

    您可以通过单击解决方案资源管理器中的项目并选择属性来打开属性窗口。在第一个选项卡上有一个用于设置入口点类的组合框。选择合适的 main 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-11
      • 1970-01-01
      • 2010-10-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多