C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » C# Syntax »

Multiple Main Methods in C#


Posted Date: 06 Nov 2008    Resource Type: Code Snippets    Category: C# Syntax
Author: Shanthi MMember Level: Gold    
Rating: 1 out of 5Points: 7



C# includes a feature that enables to define more than one class with the Main method. Since 'Main' is the entry point for program execution, there are now more than one entry points. In fact, there should be only one entry point. This problem can be resolved by specifying which Main is to be used to the compiler at the time of compilation as shown below:


csc filename.cs/main:classname


The following code snippet shows how to implement multiple Main methods in C#.


using System;

class ClassA
{
public static void Main()
{
Console.WriteLine("Class A");
}
}
class ClassB
{
public static void Main()
{
Console.WriteLine("Class B");
}
}


Save this file as 'Multimain.cs' and compile it using
csc Multimain.cs/main:ClassA if you choose ClassA as entry point
or
csc Multimain.cs/main:ClassB if you choose ClassB as entry point.





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Multiple Main Methods in C#  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Protected Members
Previous Resource: Jagged Array in C#
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use