0
0
C Sharp (C#)programming~5 mins

Main method as entry point in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the Main method in a C# program?
The Main method is the entry point of a C# program. It is where the program starts running.
Click to reveal answer
beginner
How do you declare a Main method that does not return any value?
You declare it as:
static void Main(string[] args)
This means it is static, returns nothing (void), and can accept command-line arguments.
Click to reveal answer
intermediate
Can the Main method return a value? If yes, what type?
Yes, the Main method can return an int value. This is often used to return an exit code to the operating system.
Click to reveal answer
intermediate
Why is the Main method declared as static?
Because the program starts without creating an object, the Main method must be static so it can be called by the runtime without an instance.
Click to reveal answer
advanced
What happens if you have multiple Main methods in different classes?
You must specify which Main method to use as the entry point when compiling or running the program, otherwise the compiler will give an error.
Click to reveal answer
What keyword must the Main method have to be recognized as the program's entry point?
Astatic
Bpublic
Cvoid
Dprivate
Which of these is a valid Main method signature in C#?
Astatic int Main(string args)
Bvoid Main(string[] args)
Cpublic Main()
Dstatic void Main()
What does the string[] args parameter in Main represent?
AUser input during runtime
BEnvironment variables
CCommand-line arguments
DReturn values
If Main returns an int, what does that value usually represent?
AExit code to the operating system
BNumber of lines printed
CMemory used
DNumber of errors
What happens if you omit the Main method in a C# console application?
AThe program runs with a default Main
BThe program will not compile
CThe program runs but does nothing
DThe program crashes at runtime
Explain the role and typical signature of the Main method in a C# program.
Think about how the program starts and what Main needs to do.
You got /4 concepts.
    Describe why the Main method must be static and what happens if there are multiple Main methods.
    Consider how the runtime finds and calls Main.
    You got /3 concepts.