C#方法的重载

方法的重载

参数不同,个数可以相同

参数相同,个数不能相同

        static void Main(string[] arr)
        {
            Console.WriteLine(M(2,3));
            Console.ReadKey();
        }

        public static int  M(int n1, int n2)
        { 
            n1=n1+n2;
            return n1;
        }
        public static string M(string s1, string s2)
        {
            s1 = s1 + s2;
            return s1;
        }
        public static int M(int n1, int n2,int n3)
        {
            n1 = n1 + n2+n3;
            return n1;
        }

 

posted @ 2015-05-10 15:59  自由无风  阅读(394)  评论(0编辑  收藏  举报