Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.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# 类文件中的入口点-超过1个入口点_C# - Fatal编程技术网

C# 类文件中的入口点-超过1个入口点

C# 类文件中的入口点-超过1个入口点,c#,C#,我试图在学习C#时创建一个项目,并在该项目中为每个Euler问题创建一个新类 所以我有一个base Program.cs文件,它有它的入口点 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Euler { class Program { static void

我试图在学习C#时创建一个项目,并在该项目中为每个Euler问题创建一个新类

所以我有一个base Program.cs文件,它有它的入口点

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Euler
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}
但是,我在自己的类中正确定义了入口点,并且有一个错误清楚地表明我有多个入口点

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Euler
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}
我应该如何正确设置我的条目

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Euler
{
    //Problem 1
    //If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
    //Find the sum of all the multiples of 3 or 5 below 1000.

    class Problem1
    {
        public Problem1(int args)
        {
            int num = 0;
            int limit = 1000;
            int sum = 0;
            while (num < limit)
            {
                if ((num % 3 ==0 )|| (num % 5 == 0))
                {
                    sum = sum + num;
                    num++;
                }
                else
                {
                    num++;
                }
            }
            Console.WriteLine(sum);
        }
    }


}
编辑我已解决了入口点错误,下面的代码不起作用,但由于与此问题无关的其他原因

class Problem1
    {
        public int Sum53(int args)
        {
            int num = 0;
            int limit = 1000;
            int sum = 0;
            while (num < limit)
            {
                if ((num % 3 == 0) || (num % 5 == 0))
                {
                    sum = sum + num;
                    num++;
                }
                else
                {
                    num++;
                }
            }
            return sum;
        }

        public string myValue(string args)
        {
            Console.WriteLine("This is the total :" + );
        }
    }
}
类问题1
{
公共int Sum53(int参数)
{
int num=0;
整数极限=1000;
整数和=0;
while(num
程序中只能有一个入口点(除非您告诉编译器使用哪个入口点)。但是这个入口点可以调用你想要的任何东西。因此,如果您想尝试使用多个不同的输入函数,只需取消对要运行的函数的注释即可

static void Main(string[] args) //You can't have any other functions with this signature in your project
{
    Function1(args);
    //Function3(args);
    //Function2(args);
}

static void Function1(string[] args)
{
}

static void Function2(string[] args)
{
}

static void Function3(string[] args)
{
}

我只看到一个入口。如果确实有多个,请确保在项目设置中设置启动对象。显然没有足够的信息来诊断。。。我打赌在你的整个项目中搜索“main”会发现问题。@AlexeiLevenkov不,这没有帮助。你还有其他建议吗?你的错误片段清楚地表明你在
Problem1.cs
类文件中有一个名为
main
的函数,但是您没有在这里的代码段中列出它。值得注意的是,入口点
Main
是一个特殊函数,它定义了程序启动时应运行的第一个函数。每个类文件中不需要入口点,因为实际上只有一个
.exe
,因此只有一个函数可以首先运行。可以有多个具有相同
Main
签名的函数,但如果需要,则必须使用编译器开关指示框架应链接到哪个函数。这可能比问题的基本水平高了一点,但是…@Claies是的,我提到了编译器开关,但我没有给出一个例子,因为我以前从未使用过它。请随意将其编辑到我的问题中或发布您自己的答案。它可能高于问题海报的级别,但是关于堆栈溢出的问题不仅仅是为了海报的利益:它们是为了将来遇到类似问题的所有其他人。