public class Functions
{
    public static long Factorial(int n)
    {
        if (n < 0) { return -1; }    //error result - undefined
        if (n > 256) { return -2; }  //error result - input is too big        if (n == 0) { return 1; }        // Calculate the factorial iteratively rather than recursively:        long tempResult = 1;
        for (int i = 1; i <= n; i++)
        {
            tempResult *= i;
        }
        return tempResult;
    }
}
class MainClass
{
    static int Main(string[] args)
    {
        // Test if input arguments were supplied:
        if (args.Length == 0)
        {
            System.Console.WriteLine("Please enter a numeric argument.");
            System.Console.WriteLine("Usage: Factorial <num>");
            return 1;
        }        try
        {
            // Convert the input arguments to numbers:
            int num = int.Parse(args[0]);            System.Console.WriteLine("The Factorial of {0} is {1}.", num, Functions.Factorial(num));
            return 0;
        }
        catch (System.FormatException)
        {
            System.Console.WriteLine("Please enter a numeric argument.");
            System.Console.WriteLine("Usage: Factorial <num>");
            return 1;
        }
    }
}如题,我在MSDN上找到的这个例子,但是怎么弄输出都是“Please enter a numeric argument.”到底如何能正常显示。我对命令行的参数的概念也不是了解的很透彻。
第一次发问,希望大家指点下~分儿比较少,不过尝到甜头,我以后多多充分儿!

解决方案 »

  1.   

    args这个参数数组没内容的话就总会执行
    System.Console.WriteLine("Please enter a numeric argument."); 的啊
      

  2.   


    那给出的实例上,怎么输入命令行丫?去哪儿输入丫?
    运行示例 #1:
    输入下面的命令行:Factorial 10 您将获得下面的结果:The Factorial of 10 is 3628800. 运行示例 #2:
    输入下面的命令行:Factorial 您将获得下面的结果:Please enter a numeric argument. Usage: Factorial <num> 
    谢谢您~我的分儿太少了,看了我得去多充点分儿顺便问句我怎么给您分儿而啊
      

  3.   

    开始->运行
    cmd
    cd /D 程序目录\bin\debug
    Factorial 10
      

  4.   

    ??直接输入Factorial 10???另外这个命令行参数实际意义是什么呢?真的是麻烦您了,呵呵,我很菜想问问怎么去充分儿,好给帮助我的人?