Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi Friends,

Am trying some basic concepts in OOPS using console application.
I have two classes namely program.cs and Abstractsample.cs.
Initially Program.cs is having a entry point to the project, that is start up project.
Now I want to change the entry point for the project that is application needs to start up with Abstractsample.cs.
I do have main() function in each classes, but I could not make it run.
So please help me in this regards.

Regards,
RK
Posted
Updated 12-Nov-18 4:44am
v2

Something like the following:
C#
// Abstractsample.cs
namespace ooptest
{
    class abstractsample
    {
        static void Main(string[] args)
        {
            Program pgm = new Program();
            pgm.execute()
        }

    }
}        
// Program.cs
namespace ooptest
{
    public class program
    {
        public program()
        {
            // add constructor code here
        }

        public void execute()
        {
            // add this method's code here
        }
    }
}        
 
Share this answer
 
Comments
♥…ЯҠ…♥ 10-May-13 4:09am    
Already am using this type of call to another class method. I want to know how application calls automatically that class at startup?
Richard MacCutchan 10-May-13 4:34am    
It calls it automatically because Visual Studio builds the two programs into a single executable by combining the object assemblies. Take a look at this MSDN reference page for more information.
Have main() function in one of the two classes. Not in both
 
Share this answer
 
Comments
♥…ЯҠ…♥ 10-May-13 3:07am    
I commented the main() in program.cs, now it throws "Program '\blah blah blah\InterfaceSample.exe' does not contain a static 'Main' method suitable for an entry point InterfaceSample"
tumbledDown2earth 10-May-13 3:14am    
Post your code if you can .. both main methods should have same signature
when you create a NEW PROJECT and after all the filling the all requirement your project is ready for creating programs okay.Instead of writing code in Default page ie Program.cs you have to ADD NEW ITEM and selectClass.(i use MyProgram.cs)
After naming it you start (MyProgram.cs) write code in it .Click on Project Menu and click on Set as startup page  Press F5 for Debugging code .Click on Project properties i mean click on last option on Project menu Then a Window is open Select ASSEMBLY CLLICK ON STATUP OBJECT i select i select  C_SHARP_CONSOLE.MyProgram now my statup page i mean MyProgram.cs is started executing
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900