Пример #1
0
        static void Main(string[] args)
        {
            NumberManipulator n = new NumberManipulator();

            Console.WriteLine("Factorial of 7 is: {0}", n.factorial(7));
            Console.WriteLine("Factorial of 8 is: {0}", n.factorial(8));
        }
Пример #2
0
        static void Main(string[] args)
        {
            /*local variable declaration*/
            int a = 100;
            int b = 200;
            int?c = null;
            int d;
            int ret;
            NumberManipulator n = new NumberManipulator();

            //Calling the FindMax method
            ret = n.FindMax(a, b);
            Console.WriteLine("Max value is: {0}", ret);
            for (int i = 1; i <= 13; i++)
            {
                Console.WriteLine("Factorial of {0} is: {1}", i, n.Factorial(i));
            }

            Console.WriteLine("Before method call, value of a : {0}", a);
            Console.WriteLine("Before method call, value of b : {0}", b);
            /* calling a function to get the value */
            n.getValue(out a, out b);
            Console.WriteLine("After method call, value of a : {0}", a);
            Console.WriteLine("After method call, value of b : {0}", b);

            // NUll Coalescing
            d = c ?? 5;
            Console.WriteLine(" Value of d: {0}", d);
            c = 2;
            d = c ?? 5;
            Console.WriteLine(" Value of d: {0}", d);
            Console.ReadLine();
        }
Пример #3
0
        static void Main(string[] args)
        {
            NumberManipulator n = new NumberManipulator();
            int x = 5, y = 12;

            n.swap(ref x, ref y);
            /* C#中的print format方法,结合了Python中的.format及C/C++风格的格式化方法。其中{}中必须按顺序填写值。 */
            Console.WriteLine("x = {0}, y = {1}", x, y);


            n.getValue(out x, out y);
            Console.WriteLine("x = {0}, y = {1}", x, y);

            /* 可空类型(nullable)。即在原有类型基础上,追加null值。
             * 例如数据库中的Boolean值,除了False、True,还有可能是NULL,在代码中取得数据库对应值的时候,就可以用可空类型。 */
            int?num = null;

            Console.WriteLine("num = {0}", num);

            double?num1 = null;
            double?num2 = 3.14;
            double num3, num4;

            /* null合并运算符。
             * 如果第一个操作数为null,则返回第二个操作数的值, 否则返回第一个操作数的值。 */
            num3 = num1 ?? 5.1;
            num4 = num2 ?? 5.1;
            Console.WriteLine("num3 = {0}, num4 = {1}", num3, num4);


            Console.ReadKey();
        }
Пример #4
0
        static void Main(string[] args)
        {
            /*local variable declaration*/
            int a = 100;
            int b = 200;
            int? c = null;
            int d;
            int ret;
            NumberManipulator n = new NumberManipulator();

            //Calling the FindMax method
            ret = n.FindMax(a,b);
            Console.WriteLine("Max value is: {0}", ret);
            for (int i = 1; i <= 13; i++)
            {
                Console.WriteLine("Factorial of {0} is: {1}",i , n.Factorial(i));
            }

            Console.WriteLine("Before method call, value of a : {0}", a);
            Console.WriteLine("Before method call, value of b : {0}", b);
            /* calling a function to get the value */
            n.getValue(out a, out b);
            Console.WriteLine("After method call, value of a : {0}", a);
            Console.WriteLine("After method call, value of b : {0}", b);

            // NUll Coalescing
            d = c ?? 5;
            Console.WriteLine(" Value of d: {0}", d);
            c = 2;
            d = c ?? 5;
            Console.WriteLine(" Value of d: {0}", d);
            Console.ReadLine();
        }
Пример #5
0
        static void Main(string [] args)
        {
            NumberManipulator n = new NumberManipulator();

            Console.WriteLine("6 的阶乘是: {0}", n.factorail(6));
            Console.WriteLine("7 的阶乘是: {0}", n.factorail(7));
            Console.WriteLine("8 的阶乘是: {0}", n.factorail(8));
        }
Пример #6
0
 static void Main(string[] args)
 {
     NumberManipulator n = new NumberManipulator();
     //calling the factorial method
     Console.WriteLine("Factorial of 6 is : {0}", n.factorial(6));
     Console.WriteLine("Factorial of 7 is : {0}", n.factorial(7));
     Console.WriteLine("Factorial of 8 is : {0}", n.factorial(8));
     Console.ReadLine();
 }
Пример #7
0
        static void Main(string[] args)
        {
            NumberManipulator n = new NumberManipulator();
            int a = 100;

            Console.WriteLine("在方法调用之前, a = {0}", a);
            n.getValue(out a);
            Console.WriteLine("在方法调用之后, a = {0}", a);
        }
Пример #8
0
        static void Main(string[] args)
        {
            NumberManipulator n = new NumberManipulator();

            //calling the factorial method {0}", n.factorial(6));
            Console.WriteLine("Factorial of 7 is : {0}", n.factorial(7));
            Console.WriteLine("Factorial of 8 is : {0}", n.factorial(8));
            Console.ReadLine();
        }
Пример #9
0
        static void Main(string[] args)
        {
            NumberManipulator n = new NumberManipulator();

            //调用 factorial 方法
            Console.WriteLine("6 的阶乘是: {0}", n.factorial(6));
            Console.WriteLine("7 的阶乘是: {0}", n.factorial(7));
            Console.WriteLine("8 的阶乘是: {0}", n.factorial(8));
            Console.ReadLine();
        }
Пример #10
0
        static void insideFun()
        {
            int a = 290;
            int b = 190;
            int result;
            NumberManipulator n = new NumberManipulator();

            result = n.FindMax(a, b);
            Console.WriteLine("最大值是{0}", result);
        }
Пример #11
0
        static void Main(string[] args)
        {
            NumberManipulator n = new NumberManipulator();
            int a, b, c;

            n.GetValues(out a, out b, out c);
            Console.WriteLine("a:{0}\nb:{1}\nc:{2}", a, b, c);

            Console.ReadKey();
        }
Пример #12
0
        static void Main(string[] args)
        {
            int a = 100;
            int b = 200;
            int ret;
            NumberManipulator n = new NumberManipulator();

            ret = n.FindMax(a, b);
            Console.WriteLine("最大值是:{0}", ret);
        }
Пример #13
0
        static void Main(string[] args)
        {
            int number1 = 100;
            int number2 = 200;
            int max;
            NumberManipulator nm = new NumberManipulator();

            max = nm.FindMax(number1, number2);
            Console.WriteLine("the max variable is {0}", max);
        }
Пример #14
0
        static void Main(string[] args)
        {
            double            ret;
            NumberManipulator n = new NumberManipulator();

            n.AcceptNum();
            ret = n.FindMax();
            Console.WriteLine("最大值是:{0}", ret);
            Console.ReadLine();
        }
Пример #15
0
        static void Main(string[] args)
        {
            NumberManipulator n = new NumberManipulator();
            int a, b;

            n.GetValues(out a, out b);
            Console.WriteLine("显示第一个数字:{0}", a);
            Console.WriteLine("显示第二个数字:{0}", b);
            Console.WriteLine("两个数值相加为:{0}", a + b);
            Console.ReadKey();
        }
Пример #16
0
        static void Main(string[] args)
        {
            NumberManipulator n = new NumberManipulator();
            int a, b;

            n.GetValues(out a, out b);

            WriteLine("After method call, value of a: {0}", a);
            WriteLine("After method call, value of b: {0}", b);
            ReadLine();
        }
Пример #17
0
        static void Main()
        {
            NumberManipulator n = new NumberManipulator();
            int a, b;

            n.GetValues(out a, out b);

            Console.WriteLine("在方法调用之后,a 的值: {0}", a);
            Console.WriteLine("在方法调用之后,b 的值: {0}", b);
            Console.ReadLine();
        }
Пример #18
0
        static void Main(string[] args)
        {
            /* local variable definition */
            int a = 100;
            int b = 200;
            int ret;
            NumberManipulator n = new NumberManipulator();

            //calling the FindMax method
            ret = n.FindMax(a, b);
            Console.WriteLine("Max value is : {0}", ret);
        }
Пример #19
0
 static void Main(string[] args)
 {
     /* local variable definition */
     int a = 100;
     int b = 200;
     int ret;
     NumberManipulator n = new NumberManipulator();
     //calling the FindMax method
     ret = n.FindMax(a, b);
     Console.WriteLine("Max value is : {0}", ret);
     Console.ReadLine();
 }
Пример #20
0
        static void Main(string[] args)
        {
            NumberManipulator n = new NumberManipulator();
            int a = 100;
            int b = 200;

            Console.WriteLine("在交换之前,a的值:{0}", a);
            Console.WriteLine("在交换之前,b的值:{0}", b);
            n.swap(ref a, ref b);
            Console.WriteLine("在交换之前,a的值:{0}", a);
            Console.WriteLine("在交换之前,b的值:{0}", b);
        }
Пример #21
0
        static void Main(string[] args)
        {
            NumberManipulator n = new NumberManipulator();

            int a = 100;

            Console.WriteLine("Before method call, value of a: {0}", a);

            n.getValue(out a);

            Console.WriteLine("After Methid call, value of a: {0}", a);
        }
Пример #22
0
        static void Main(string[] args)
        {
            NumberManipulator n = new NumberManipulator();

            /* local variable definition */
            int a, b;

            /* calling a function to get the values */
            n.getValues(out a, out b);

            Console.WriteLine("After method call, value of a : {0}", a);
            Console.WriteLine("After method call, value of b : {0}", b);
        }
        static void Main(string[] args)
        {
            //locla variables, again
            int a = 100;
            int b = 200;
            int ret;
            NumberManipulator n = new NumberManipulator();

            //Finally, call findmax method
            ret = n.FindMax(a, b);
            Console.WriteLine("Max value is : {0}", ret);
            Console.ReadLine();
        }
Пример #24
0
        static void Main(string[] args)
        {
            /* 局部变量定义 */
            int a = 100;
            int b = 200;
            int ret;
            NumberManipulator n = new NumberManipulator();

            //调用 FindMax 方法
            ret = n.FindMax(a, b);
            Console.WriteLine("最大值是: {0}", ret);
            Console.ReadLine();
        }
Пример #25
0
        static void Main(string[] args)
        {
            /* 局部变量定义 */
            int a = 100;
            int b = 200;
            int ret;
            NumberManipulator n = new NumberManipulator();

            //调用 FindMax 方法
            ret = n.FindMax(a, b);
            Console.WriteLine("最大值是: {0}", ret);
            Console.ReadLine();
        }
Пример #26
0
        static void Main(string[] args)
        {
            NumberManipulator n = new NumberManipulator();
            /* local variable definition */
            int a = 100;

            Console.WriteLine("Before method call, value of a : {0}", a);

            /* calling a function to get the value */
            n.getValue(out a);

            Console.WriteLine("After method call, value of a : {0}", a);
            Console.ReadLine();
        }
Пример #27
0
        static void Main(string[] args)
        {
            NumberManipulator n = new NumberManipulator();
            int a = 100;
            int b = 200;

            Console.WriteLine("在交换之前,a={0}", a);
            Console.WriteLine("在交换之前,b={0}", b);

            n.swap(a, b);
            Console.WriteLine("在交换之前,a={0}", a);
            Console.WriteLine("在交换之前,b={0}", b);

            Console.ReadLine();
        }
Пример #28
0
        static void Main(string[] args)
        {
            NumberManipulator n = new NumberManipulator();

            int a = 100;
            int b = 200;

            Console.WriteLine("Before swap, value of a: {0}", a);
            Console.WriteLine("Before swap, value of b: {0}", b);

            n.swap(ref a, ref b);

            Console.WriteLine("After swap, value of a: {0}", a);
            Console.WriteLine("After swap, value of b: {0}", b);
        }
Пример #29
0
        static void Main(string[] args)
        {
            NumberManipulator n = new NumberManipulator();

            /* local variable definition */
            int a = 100;
            int b = 200;

            Console.WriteLine("Before swap, value of a : {0}", a);
            Console.WriteLine("Before swap, value of b : {0}", b);

            /* calling a function to swap the values */
            n.swap(a, b);

            Console.WriteLine("After swap, value of a : {0}", a);
            Console.WriteLine("After swap, value of b : {0}", b);
        }
Пример #30
0
        static void Main(string[] args)
        {
            /* local variable definintion */
            int a = 100;
            int b = 200;
            int ret;
            NumberManipulator n = new NumberManipulator();

            int?num1 = null;
            int?num2 = 45;

            double?num3 = new double?();
            double?num4 = 3.14157;

            bool?boolval = new bool?();

            double?num5 = null;
            double?num6 = 3.14157;
            double num7;

            //calling the FindMax method
            ret = n.FindMax(a, b);
            Console.WriteLine("Max value is : {0}", ret);
            Console.ReadLine();

            //calling the factorial method
            Console.WriteLine("Factorial of 6 is : {0}", n.factorial(6));
            Console.WriteLine("Factorial of 7 is : {0}", n.factorial(7));
            Console.WriteLine("Factorial of 8 is : {0}", n.factorial(8));
            Console.ReadLine();

            // display the values
            Console.WriteLine("Nullables at Show: {0}, {1}, {2}, {3}", num1, num2, num3, num4);
            Console.WriteLine("A Nullable boolean value: {0}", boolval);
            Console.ReadLine();

            //Null Coalescing Operator (??)
            num7 = num5 ?? 5.34;
            Console.WriteLine(" Value of num3: {0}", num7);

            num7 = num6 ?? 5.34;
            Console.WriteLine(" Value of num3: {0}", num7);
            Console.ReadLine();
        }
Пример #31
0
        static void Main(string[] args)
        {
            /* local variable definition */
            int a;
            int b;
            int ret;
            NumberManipulator n = new NumberManipulator();



            Console.WriteLine("Enter a number:");
            a = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter a number:");
            b = Convert.ToInt32(Console.ReadLine());
            //calling the FindMax method
            ret = n.FindMax(a, b);
            Console.WriteLine("Max value is : {0}", ret);
            Console.ReadLine();
        }
Пример #32
0
        static void Main(string[] args)
        {
            NumberManipulator n = new NumberManipulator();
            /* 局部变量定义 */
            int a = 100;
            int b = 200;

            Console.WriteLine("在交换之前,a 的值: {0}", a);
            Console.WriteLine("在交换之前,b 的值: {0}", b);

            n.swapval(a, b);
            Console.WriteLine("1在交换之后,a 的值: {0}", a);
            Console.WriteLine("1在交换之后,b 的值: {0}", b);

            /* 调用函数来交换值 */
            n.swap(ref a, ref b);

            Console.WriteLine("2在交换之后,a 的值: {0}", a);
            Console.WriteLine("2在交换之后,b 的值: {0}", b);

            Console.ReadLine();
        }
Пример #33
0
        static void Main(string[] args)
        {
            NumberManipulator n = new NumberManipulator();
            /* 局部变量定义 */
            int a, b;
            int c = 0, d = 0;

            /* 调用函数来获取值 */
            n.getValues1(out a, out b);
            Console.WriteLine("在方法调用之后,a 的值: {0}", a);
            Console.WriteLine("在方法调用之后,b 的值: {0}", b);

            //引用传递必须要是已经赋值的内容
            n.getValues2(ref c, ref d);

            /** 否则会报错
             * CalcuApp.cs(36,30): error CS0165: 使用了未赋值的局部变量“c”
             * CalcuApp.cs(36,37): error CS0165: 使用了未赋值的局部变量“d”
             **/
            Console.WriteLine("在方法调用之后,c 的值: {0}", c);
            Console.WriteLine("在方法调用之后,d 的值: {0}", d);
            Console.ReadLine();
        }
Пример #34
0
        static void Main(string[] args)
        {
            int a = 100;
            int b = 200;
            int ret;
            NumberManipulator n = new NumberManipulator();

            ret = n.FindMax(a, b);
            Console.WriteLine("最大值:{0}", ret);
            Console.WriteLine("6的阶乘是{0}", n.factorial(6));
            Console.WriteLine("7的阶乘是{0}", n.factorial(7));
            int c = 222;
            int d = 333;

            Console.WriteLine("按值传参交换之前的c是=>{0}", c);
            Console.WriteLine("按值传参交换之前的d是=>{0}", d);
            n.swap(c, d);
            Console.WriteLine("按值传参交换之后的c是=>{0}", c);
            Console.WriteLine("按值传参交换之后的d是=>{0}", d);
            int e = 123;
            int f = 321;

            Console.WriteLine("按引用传递参数交换之前的e是=>{0}", e);
            Console.WriteLine("按引用传递参数交换之前的f是=>{0}", f);
            n.refSwap(ref e, ref f);
            Console.WriteLine("按引用传递参数交换之后的e是=>{0}", e);
            Console.WriteLine("按引用传递参数交换之后的f是=>{0}", f);
            int g = 158;

            Console.WriteLine("按输出传递参数调用函数之前的g是=>{0}", g);
            n.getValue(out g);
            Console.WriteLine("按输出传递参数调用函数之后的g是=>{0}", g);
            int aa, bb;

            n.getNoValue(out aa, out bb);
            Console.WriteLine("按输出传递参数调用函数之后的aa=>{0},bb是=>{1}", aa, bb);
        }