Challenge - 5 Problems
Main Method Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this C# program?
Consider this C# program with a Main method. What will it print when run?
C Sharp (C#)
using System; class Program { static void Main(string[] args) { Console.WriteLine("Hello from Main!"); } }
Attempts:
2 left
💡 Hint
The Main method is the entry point and runs automatically.
✗ Incorrect
The Main method is the starting point of a C# console application. It runs and prints the string to the console.
❓ Predict Output
intermediate2:00remaining
What happens if Main method has wrong signature?
What will happen if the Main method is declared without static keyword in C#?
C Sharp (C#)
using System; class Program { void Main(string[] args) { Console.WriteLine("Hello"); } }
Attempts:
2 left
💡 Hint
Main method must be static because it is called by runtime without an instance.
✗ Incorrect
In C#, the Main method must be static because the runtime calls it without creating an object instance. Omitting static causes a compile-time error.
❓ Predict Output
advanced2:00remaining
What is the output of this overloaded Main method program?
This program has two Main methods. What will it print when run?
C Sharp (C#)
using System; class Program { static void Main() { Console.WriteLine("Main without args"); } static void Main(string[] args) { Console.WriteLine("Main with args"); } }
Attempts:
2 left
💡 Hint
When running from command line, Main with string[] args is called by default.
✗ Incorrect
The C# runtime calls the Main method with string[] args if it exists. So it prints "Main with args".
🧠 Conceptual
advanced2:00remaining
Which Main method signature is valid as entry point?
Select the only valid Main method signature that can be used as the entry point in a C# console application.
Attempts:
2 left
💡 Hint
Main must be static and can have string[] args parameter.
✗ Incorrect
Valid Main signatures include static void Main(string[] args) or static int Main(). The method must be static and have correct parameter types.
❓ Predict Output
expert2:00remaining
What is the output of this program with async Main?
This program uses async Main method. What will it print when run?
C Sharp (C#)
using System; using System.Threading.Tasks; class Program { static async Task Main() { await Task.Delay(100); Console.WriteLine("Async Main finished"); } }
Attempts:
2 left
💡 Hint
Modern C# supports async Main returning Task.
✗ Incorrect
Since C# 7.1, async Main returning Task is supported. The program waits 100ms then prints the message.