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

Main method as entry point in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Main Method Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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!");
    }
}
AHello from Main!
BNo output, program compiles but does nothing
CCompilation error: Main method missing return type
DRuntime error: Main method not found
Attempts:
2 left
💡 Hint
The Main method is the entry point and runs automatically.
Predict Output
intermediate
2: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");
    }
}
AProgram compiles but does nothing
BProgram runs and prints Hello
CRuntime error: Main method not found
DCompilation error: Main method must be static
Attempts:
2 left
💡 Hint
Main method must be static because it is called by runtime without an instance.
Predict Output
advanced
2: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");
    }
}
AMain with args
BMain without args
CCompilation error: duplicate Main methods
DRuntime error: ambiguous entry point
Attempts:
2 left
💡 Hint
When running from command line, Main with string[] args is called by default.
🧠 Conceptual
advanced
2: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.
Astatic int Main()
Bpublic static void Main(string[] args)
Cvoid Main()
Dpublic void Main(string args)
Attempts:
2 left
💡 Hint
Main must be static and can have string[] args parameter.
Predict Output
expert
2: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");
    }
}
ARuntime error: Task not awaited
BCompilation error: async Main not supported
CAsync Main finished
DNo output, program exits immediately
Attempts:
2 left
💡 Hint
Modern C# supports async Main returning Task.