C# 方法使用 0007

FindMax number method

using System;

namespace CalculatorApplication
{

    class NumberManipulator
    {
        public int FindMax(int num1,int num2)
        {
            //local variable declaration
            int result;
            if (num1 > num2)
            {
                return num1;
            }
            else
                return num2;
            return result;
        }
        static void Main(string[] args)
        {
            //local variable declaration
            int a = 100;
            int b = 200;
            int ret;
            NumberManipulator n = new NumberManipulator();
            ret = n.FindMax(a,b);
           Console.WriteLine("Max value is : {0}",ret);
            Console.ReadLine();
        }
    }
}

output:
Max value is : 200


Recursive Method Call

using System;

namespace CalculatorApplication
{

    class NumberManipulator
    {
        public int factorial(int num)
        {
            //local variable declaration
            int result;
            if (num==1)
            {
                return 1;
            }
            else
                result= factorial(num-1)*num;
            return result;
        }
        static void Main(string[] args)
        {
             NumberManipulator n = new NumberManipulator();

           Console.WriteLine("Factorial of 6 is : {0}", n.factorial(6));
            Console.ReadLine();
        }
    }
}

Factorial of 6 is :720


using System;

namespace CalculatorApplication
{
    class NullablesAtShow
    {
        static void Main(string[] args)
        {
            int? num1 = null;
            double? num2 = 24;
            double? num3 = new double();
            double? num4 = 3.1415;
                bool? boolval = new bool?();
            // 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();
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值