Overloading Main function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anil

    #1

    Overloading Main function


    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

  • 100

    #2
    Re: Overloading Main function

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

    }
    }


    "Anil" <adogra@greenfi eld.com> wrote in message
    news:116001c3a2 50$ea34fb50$a00 1280a@phx.gbl.. .[color=blue]
    >
    > 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
    >[/color]


    Comment

    Working...