我想要做的是在學習C#時創建一個項目,併爲每個Euler問題在該項目中創建一個新類。類文件中的入口點 - 超過1個入口點
所以我有一個基地的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
{
//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);
}
}
}
我知道這是一個新手,但它似乎並不明顯。
Error 1 Program 'c:\Users\Sayth\Documents\Visual Studio 2013\Projects\Euler\Euler\obj\Debug\Euler.exe' has more than one entry point defined: 'Euler.Program.Main(string[])'. Compile with /main to specify the type that contains the entry point. c:\users\sayth\documents\visual studio 2013\Projects\Euler\Euler\Program.cs 11 21 Euler
Error 2 Program 'c:\Users\Sayth\Documents\Visual Studio 2013\Projects\Euler\Euler\obj\Debug\Euler.exe' has more than one entry point defined: 'Euler.Problem1.Main(string[])'. Compile with /main to specify the type that contains the entry point. c:\users\sayth\documents\visual studio 2013\Projects\Euler\Euler\Problem1.cs 15 21 Euler
編輯我已經解決了入口點錯誤,下面的代碼並不但都沒有涉及這個問題的其他原因的工作。
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 :" +);
}
}
}
我在那裏只看到一個入口點。如果您確實有多個,請確保在您的項目設置中設置啓動對象。 – BradleyDotNET
顯然沒有足夠的信息來診斷......我敢打賭,在整個項目中搜索「主」會揭示問題。 –
@AlexeiLevenkov不,你沒有任何其他建議嗎? – sayth