Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to make 2 files in

I am trying to make one file for each of the tutorials from Brakeys c#. When I try and make and run the new file or the old one once it has been created it says that I have multiple entry points, What does this mean and what is the solution? I created the new file by right clicking under the folder and pressing new class. I then added using system and everything between public class.I ran it while the second program(switchstatement) was open. What should I do to run them separately and work.I am on a mac.


Answers

  • You can only have 1 'Main' function per project.

    If you want to keep it all in the same project, you can take whatever is in the main, and move it to its own function. Then in the 1 Main function, just call the function you made for whichever tutorial you want to run.

    Otherwise, you need to make an entire new project to have another Main

  • How do you call or create a function? Could you show me an example or link to a tutorial? I don't want to get in over my head as I have little c# experience so I am afraid of not understanding the terminology.

  • edited July 28

    Well, i made all the tutorial in one file, when i want to make a new one, i turn the old one into comment, like this

    and it's the new one

    hope this can help, probably there are better ways, im kinda new too, but at least that's how i do it

    ps : ignore the "new" program tho, im just messing around

  • edited July 29

    also making another function, here's the example :

    static void Main(string[] args)
            {
                ProgramThatPrintHelloWorld();
                Console.ReadKey();
            }
    
    
    public static void ProgramThatPrintHelloWorld()
            {
                Console.WriteLine("Hello World!");
            }
    
    

    Type this outside the Main's bracket, TheNameOfTheFunction is actually up to you.

    public static void TheNameOfTheFunction()
    {
    // Whatever your program is 
    }
    

    and then called TheNameOfTheFunction() in Main's bracket

    static void main(string[] args)
    {
    TheNameOfTheFunction();
    }
    

    cmiiw

Sign In or Register to comment.