C# MULTIPLE MAIN CLASSES / MAIN METHODS – In this tutorial, you will learn, how to run multiple main methods in c# using manual and automated methods with example.
- It is possible to handle a c# program with more than one entry point (Main())
- If a class contains main method then it is called as “Main Class”
- C# supports multiple main methods
- Main() is the entry point for program execution. Without main() method, we can’t get the target output
- This is implemented with help of /main switch
- The /main switch must be given at the time of the compilation.
EXAMPLE COMMANDS for MANUAL COMPILATION
I. PROGRAM WITH MULTIPLE MAIN METHODS
(MultipleMainClasses.cs)
1. SOURCE CODE
using x=System.Console; // Here ‘x’ is an alias
// 1st Entry Point
class A
{
static void Main()
{
x.WriteLine(“Class A:\n\tMain method is calling”);
}
}
// 2nd Entry Point
class B
{
static void Main()
{
x.WriteLine(“Class B:\n\tMain method is calling”);
}
}
// 3rd Entry Point
class C
{
static void Main()
{
x.WriteLine(“Class C:\n\tMain method is calling”);
}
}
2. VISUAL STUDIO IDE AUTOMATIC CONFIGURATION
- Initially no main method is selected in the startup object, we need to select.
- Open Project Properties by just right clicking on the project and select “Properties“.
- Click on the Application Tab.
- Select the target main class which you want to execute as given below in figure.
SCREENSHOT EXAMPLE
2.1 VS IDE OUTPUT
3. VS CMD OUTPUT (MANUEL PROCEDURE)
3.1 ERROR MESSAGE: RUNNING WITHOUT USING /main SWITCH
3.2 RUNNING MAIN CLASS “A” USING /main SWITCH
3.3 RUNNING MAIN CLASS “B” USING /main SWITCH
3.4 RUNNING MAIN CLASS “C” USING /main SWITCH
MORE TUTORIALS
-
How to convert Word to Number in Bash Script
FacebookTweetPinLinkedInEmailShares0SharePrint In this bash tutorial, you will get convert word to number in bash script with examples.This is implemented using for loop, tr command, switch case in shell…
-
How to Count Word Frequency in Bash Script
FacebookTweetPinLinkedInEmailShares0SharePrint In this bash tutorial, you will get the program about how to count word frequency in bash script. This is done by using for loop,…
-
Bash Script – How to convert Number to Words
FacebookTweetPinLinkedInEmailShares0SharePrint In this tutorial, you will see how to convert numbers to words using bash script. This shell script can be done with the help of switch case…