Monday, 17 November 2025

Overloading Main Method

Overloading Main Method

Can You Overload the Main Method in C#?

Yes, you can overload the Main method in C#, but only one serves as the program's entry point.

Example:

class Program { static void Main(string[] args) { Console.WriteLine("Main with string[] args"); Main(10); } static void Main(int number) { Console.WriteLine("Overloaded Main with int: " + number); } static void Main(double value) { Console.WriteLine("Overloaded Main with double: " + value); } }

Key Points:

  • You can overload Main like any other method.
  • Only one method is used as the entry point.
  • Overloaded Main methods must be called manually.

No comments:

Post a Comment