C#中有關方法的宣告和呼叫

iamzxf發表於2015-03-18


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace methodDemo
{
    class SimpleMath
    {
        public int add(int x, int y)
        {
            return x + y;
        }
        public static int Max(int x, int y)
        {
            if (x > y)
                return x;
            else
                return y;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());

            SimpleMath smp = new SimpleMath();
            Console.WriteLine(smp.add(a,b));
            Console.WriteLine(SimpleMath.Max(a,b));
            Console.ReadLine();

        }
    }
}



相關文章