fun1(string str1,string str2)
{
}
fun2(int a,string str)
{
}
static void Main()
{
//what should i do in here when i want to pass parameters to functions via cmd windows? like : (c:\exam.exe fun1 abc cde) or (c:\exam.exe fun2 100 abc)
}
Thanks.
fun1(string str1,string str2)
{
}
fun2(int a,string str)
{
}
static void Main()
{
//what should i do in here when i want to pass parameters to functions via cmd windows? like : (c:\exam.exe fun1 abc cde) or (c:\exam.exe fun2 100 abc)
}
Thanks.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
blackPosted Mar 11, 2008, 10:43 AM
Thanks for your helps.I will check it right now.
Hope you have a good day!
AlanPosted Mar 11, 2008, 8:27 AM
If you're wanting to pass command line arguments to the current program, you need to use the version of Main which takes a string array as an argument. Something like this:
class Program
{
fun1(string str1,string str2)
{
}
fun2(int a,string str)
{
}
static void Main(string[] args)
{
if (args.Length ! = 3)
{
Console.WriteLine("Program failure, there must be exactly three arguments");
return;
}
Program p = new Program();
string fun = args[0];
if (fun == "fun1")
{
p.fun1(args[1], args[2]);
}
else if (fun == "fun2")
{
p.fun2(int.Parse(args[1]), args[2]);
}
else
{
Console.WriteLine("Program failure, method must be called fun1 or fun2");
}
}
}
If exam.exe is an external program which is expecting command line arguments in this form, then use:
System.Diagnostics.Process.Start("exam.exe", "fun1 abc cde");
System.Diagnostics.Process.Start("exam.exe", "fun2 100 abc");