string[] args 如何输入值?
args是程序运行时采用的一个参数,那么如何将值传入。下面示例中怎么出入args的值,可能问题有些弱智,希望大侠们发点时间解答。谢谢。using System;
public class Factorial
{
public static long Fac(long i)
{
return ((i <= 1) ? 1 : (i * Fac(i-1)));
}
}class MainClass
{
public static int Main(string[] args)
{
// Test if input arguments were supplied:
if (args.Length == 0)
{
Console.WriteLine("Please enter a numeric argument.");
Console.WriteLine("Usage: Factorial <num>");
return 1;
} // Convert the input arguments to numbers:
try
{
long num = long.Parse(args[0]);
Console.WriteLine("The Factorial of {0} is {1}.",num, Factorial.Fac(num));
return 0;
}
catch (System.FormatException)
{
Console.WriteLine("Please enter a numeric argument.");
Console.WriteLine("Usage: Factorial <num>");
return 1;
}
}
}
args是程序运行时采用的一个参数,那么如何将值传入。下面示例中怎么出入args的值,可能问题有些弱智,希望大侠们发点时间解答。谢谢。using System;
public class Factorial
{
public static long Fac(long i)
{
return ((i <= 1) ? 1 : (i * Fac(i-1)));
}
}class MainClass
{
public static int Main(string[] args)
{
// Test if input arguments were supplied:
if (args.Length == 0)
{
Console.WriteLine("Please enter a numeric argument.");
Console.WriteLine("Usage: Factorial <num>");
return 1;
} // Convert the input arguments to numbers:
try
{
long num = long.Parse(args[0]);
Console.WriteLine("The Factorial of {0} is {1}.",num, Factorial.Fac(num));
return 0;
}
catch (System.FormatException)
{
Console.WriteLine("Please enter a numeric argument.");
Console.WriteLine("Usage: Factorial <num>");
return 1;
}
}
}
string[] csdn={"a","b"};
Main(csdn);
那么:args={1,2,3}
命令行?
D:\ a 1 2 3
快捷方式 新建a的快捷方式---------->属性----------->
"D:\a.exe"
改成
"D:\a.exe" 1 2 3
进程:
Process p = new Process();
ProcessStartInfo ps = new ProcessStartInfo("FileName", "1 2 3");
p.StartInfo = ps;
p.Start();