增加了一个新的类到我的项目,并得到错误说Program.Main()有一个以上的条目,为什么? [英] Added a new class to my project and get error say Program.Main() has more then one entry why?

查看:490
本文介绍了增加了一个新的类到我的项目,并得到错误说Program.Main()有一个以上的条目,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是,之后,我添加了新的类错误来到了,当我做构建解决方案。 ?什么都可以错



在Form1上我没有任何的代码,但



刚添加了新的类:

 使用系统; 
使用System.Collections.Generic;
使用System.Linq的;
使用System.Text;
使用OpenHardwareMonitor.Hardware;

命名空间OpenHardwareMonitorReport
{

类节目
{

静态无效的主要(字串[] args)
{
电脑电脑=新计算机();
computer.Open();

变种临时工=新的List<&小数GT;();
的foreach(在computer.Hardware VAR硬件)
{
如果(hardware.HardwareType = HardwareType.CPU!)
继续;
hardware.Update();
的foreach(在hardware.Sensors VAR传感器)
{
如果(sensor.SensorType!= SensorType.Temperature)
{
如果(sensor.Value!= NULL )
temps.Add((十进制)sensor.Value);
}
}
}

的foreach(以临时工十进制临时)
{
Console.WriteLine(TEMP);
}
到Console.ReadLine();
}
}
}



然后,我看到的Program.cs并在主要错误()

 使用系统; 
使用System.Collections.Generic;
使用System.Linq的;使用System.Windows.Forms的
;

命名空间NvidiaTemp
{
静态类节目
{
///<总结>
///的主入口点应用程序。
///< /总结>
[STAThread]
静态无效的主要()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(假);
Application.Run(新Form1中());
}
}
}

错误2计划D:\C-Sharp\NvidiaTemp\NvidiaTemp\NvidiaTemp\obj\x86\\ \\Debug\NvidiaTemp.exe'有多个定义的切入点:NvidiaTemp.Program.Main()。用/主编译指定包含入口点的类型。 D:\C-Sharp\NvidiaTemp\NvidiaTemp\NvidiaTemp\Program.cs 14 21 NvidiaTemp


解决方案

C#程序只能有一个Program.Main()。主要是在程序启动时,所以编译器需要知道哪一个才是真正的之一,它可以,如果你有没有两个第一方法运行。



据看起来你正在做一个Windows应用程序。您应该代码添加到存在的主要,或将其添加到您的主要形式触发事件处理程序。


The problem is that after i added the new class the error came up when i did build the solution. What can be wrong ?

In Form1 i dont have any code yet.

Just added new class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenHardwareMonitor.Hardware;

namespace OpenHardwareMonitorReport
{

    class Program
    {

        static void Main(string[] args)
        {
            Computer computer = new Computer();
            computer.Open();

            var temps = new List<decimal>();
            foreach (var hardware in computer.Hardware)
            {
                if (hardware.HardwareType != HardwareType.CPU)
                    continue;
                hardware.Update();
                foreach (var sensor in hardware.Sensors)
                {
                    if (sensor.SensorType != SensorType.Temperature)
                    {
                        if (sensor.Value != null)
                            temps.Add((decimal)sensor.Value);
                    }
                }
            }

            foreach (decimal temp in temps)
            {
                Console.WriteLine(temp);
            }
            Console.ReadLine();
        }
    }
}

Then i see Program.cs and error on Main()

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace NvidiaTemp
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

Error   2   Program 'D:\C-Sharp\NvidiaTemp\NvidiaTemp\NvidiaTemp\obj\x86\Debug\NvidiaTemp.exe' has more than one entry point defined: 'NvidiaTemp.Program.Main()'.  Compile with /main to specify the type that contains the entry point.   D:\C-Sharp\NvidiaTemp\NvidiaTemp\NvidiaTemp\Program.cs  14  21  NvidiaTemp

解决方案

A C# program can only have one Program.Main(). Main is the first method run when the program starts, so the compiler needs to know which one is the real one, and it can't if you have two.

It looks like you're making a Windows application. You should either add code to the existing main, or add it to an event handler triggered by your main form.

这篇关于增加了一个新的类到我的项目,并得到错误说Program.Main()有一个以上的条目,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆