Overloading Main function

  • Thread starter Thread starter Anil
  • Start date Start date
A

Anil

Following is a code snippet

using System;
class clsX
{
public static void Main(string [] args)
{

}
public static void Main(int x, int y)
{

}
}

I want to call the

public static void Main(int x, int y)

function from the command line.

How should, i go for that?

Regards
Anil
 
Hi Anil,
Your Main method might have no parameters or one parameter which is array of
strings
For the overload with parameter its prototype could be one of the following
static int Main(string[] args)
or
static void Main(string[] args)

What you might wanna do is to extract the two integers form the command line
argumens and call your specialized overload.

using System;
class clsX
{
public static void Main(string [] args)
{
int x, y;
try
{
x = int.Parse(args[0]);
y = int.Parse(args[1]);
}
catch(Exception)
{
//Report wrong command-line params
return;
}
Main(x,y);

}
public static void Main(int x, int y)
{

}
}
 
Back
Top