building project having many main class

Hi

I want to build a project which contains classes each of them having own main method.

Is it possible for me to compile the project without specifying starting class(class with main)

(i can specify starting class during execution).

This is possible with Eclipse IDE used for Java. The starting class is need to be specified only during execution.

Could any body help me in this

Thanks
Natarajan Arumugam.


Answer this question

building project having many main class

  • Andrew Mercer

    You can create a new class with its own main function and set that to be the starting main and then have that new main call the old ones appropriately, provided they are declared as (or you can change their declaration to be) public or internal (if compiled in the same assembly) members of their respective classes.  But in the end you do need to have a single main set as the startup main if all of them are to be compiled to the same executable assembly.

    If you are looking to build them all into a library dll then you can compile them without specifying a startup by setting the output to "Class Library".

    Lastly you can compile each to their own executable by making each one a seperate project under the same solution and then simply referencing the various executables.

    Those are the three ways I can think of to do that.


  • MariaD

    You can have only one Main method. But this doesn't stop you from starting different classes depending on some parameter in runtime. Main method is just the begining of app. In this method you can decide what to do next, which form to start or which class to instance and use it.
    From VS 2005 has removed the project property of Starting Form, because now VS adds Program class for every project where the main method is placed. In this main method you will see which form will be activated first.

  • Robs Pierre

    Hope i should be more clear. My project contains 2-3 classes having main method. Is it possible for me to build the soln
  • XNA Rockstar

    Natarajan Arumugam wrote:
    Hope i should be more clear. My project contains 2-3 classes having main method. Is it possible for me to build the soln

    You cannot compile a project having more than one main functions in it. You must have only one entry point in a single project but can be more than 1 in a solution (in different projects under the same solution).

    Best Regards,

    Rizwan



  • building project having many main class