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)
{

}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Use of event handling 6
tostring 3
Is it based up polymorphy or just inheritance? 2
interface 1
same assembly size for debug and release 2
Calling a C-function from C# ??? 7
? 7
run time error 3

Back
Top