test.cs

来自「csharp-solution,C#高效编程源码」· CS 代码 · 共 58 行

CS
58
字号
namespace Utils
{
    using System;

    /// <summary>
    ///   This the test harness
    /// </summary>

    public class Test
    {
        public static void Main() 
        {
            int x;       // input value 1
            int y;       // input value 2
            int greater; // result from Greater()
            int f;       // factorial result
            bool ok;     // factorial success/failure

            // Get input numbers
            Console.WriteLine("Enter first number:");
            x = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter second number:");
            y = int.Parse(Console.ReadLine());

            // Test the Greater() method
            greater = Utils.Greater(x,y);
            Console.WriteLine("The greater value is ", greater);

            // Test the Swap() method
            Console.WriteLine("Before swap: " + x + "," + y);
            Utils.Swap(ref x,ref y);
            Console.WriteLine("After swap: " + x + "," + y);

            // Get input for factorial

            Console.WriteLine("Number for factorial:");
            x = int.Parse(Console.ReadLine());

            // Test the factorial function
            ok = Utils.Factorial(x, out f);
            // Output factorial results
            if (ok)
                Console.WriteLine("Factorial(" + x + ") = " + f);
            else
                Console.WriteLine("Cannot compute this factorial");

            // Test the factorial function (recursive version)

            ok = Utils.RecursiveFactorial(x, out f);

            if (ok)
                Console.WriteLine("Factorial(" + x + ") = " + f + " (recursive)");
            else
                Console.WriteLine("Cannot compute this factorial (recursive)");
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?