コード例 #1
0
ファイル: Program.cs プロジェクト: DanielHang/Training
        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();
        }
コード例 #2
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();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: DanielHang/Training
        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();
        }
コード例 #4
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);
        }
コード例 #5
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);
        }
コード例 #6
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();
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: Aries-xmz/learn_csharp
        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);
        }