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
Mainlike any other method. - Only one method is used as the entry point.
- Overloaded
Mainmethods must be called manually.
No comments:
Post a Comment