views:

627

answers:

3

Hello everybody;

I have the next question. I have an application lets call it A and a B application, both C# FWK 2.0 and WINFORMS.

In application A I want to open application B passing a parameter to it, but as you know... I cant change the

  static void main()
  {
  }

Any suggestions????

Best Regards!!!

+3  A: 
static void Main(string[] args)
{
}
Thomas
input: "whatever.exe -v foo /lol nisp". Output: args[0] = "-v"; args[1] = "foo"; args[2] = "/lol"; args[3] = "nisp"; What could be easier?
Callum Rogers
Thank you! Smooth
MRFerocius
+1  A: 

You can grab the command line of any .Net application by accessing the Environment.CommandLine property. It will have the command line as a single string but parsing out the data you are looking for shouldn't be terribly difficult.

Having an empty Main method will not affect this property or the ability of another program to add a command line parameter.

JaredPar
Or use Environment.GetCommandLineArgs() which returns an string array of arguments just like Main(string[] args)
Brettski
A: 

You use this signature: (in c#) static void Main(string[] args)

This article may help to explain the role of the main function in programming as well: http://en.wikipedia.org/wiki/Main_function_(programming)

Here is a little example for you: class Program { static void Main(string[] args) { bool doSomething = false;

        if (args.Length > 0 && args[0].Equals("doSomething"))
            doSomething = true;

        if (doSomething) Console.WriteLine("Commandline parameter called");
    }
}
chrisghardwick