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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
AlanRank #669 · 3.6K reputationPosted Mar 11, 2008, 4:27 AM EDT
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");
black5 reputationPosted Mar 11, 2008, 6:43 AM EDT
Thanks for your helps.I will check it right now.
Hope you have a good day!