c# - Entry point in class file - More than 1 entry point -
what trying create project learn c# , have new class in project each euler problem.
so have base program.cs file has entry point.
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) { } } }
however defining entry point in own class correctly , have error showing have more 1 entry point.
how should set entry correctly?
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace euler { //problem 1 //if list natural numbers below 10 multiples of 3 or 5, 3, 5, 6 , 9. sum of these multiples 23. //find sum of 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); } } }
i know newbie thing doesn't seem obvious.
error 1 program 'c:\users\sayth\documents\visual studio 2013\projects\euler\euler\obj\debug\euler.exe' has more 1 entry point defined: 'euler.program.main(string[])'. compile /main specify type contains 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 1 entry point defined: 'euler.problem1.main(string[])'. compile /main specify type contains entry point. c:\users\sayth\documents\visual studio 2013\projects\euler\euler\problem1.cs 15 21 euler
edit have resolved entry point errors, code below doesn't work other reasons not related question.
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 total :" + ); } } }
you can have single entry point in program (unless tell compiler otherwise 1 use). entry point can call whatever want. if wanted have multiple different entry functions experimenting with, can uncomment function want run.
static void main(string[] args) //you can't have other functions signature in project { function1(args); //function3(args); //function2(args); } static void function1(string[] args) { } static void function2(string[] args) { } static void function3(string[] args) { }
Comments
Post a Comment