C # method overloading

Source: Internet
Author: User

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 ////////////////////////////////////////////////////6 //method overloads:7 //1. Method names must be the same8 //2. The number of parameters must be different (if the number of arguments is the same, then the type must be different)9 //3. Parameter types must be differentTen //4. Independent of return value One //////////////////////////////////////////////////// A namespaceMethod Overloading - { -     class Program the     { -         Static voidMain (string[] args) -         { -             //Method overloading 1 + test_overloaded_methods (); -             //Method Overloading 2 +Test_overloaded_methods ("I'm the method. Overload 2: A parameter that is of type string"); A             //Method Overloading 3 atTest_overloaded_methods (3); -             //Method Overloading 4 -Test_overloaded_methods (4,"Overload 4"); -             //Method Overloading 5 -Test_overloaded_methods ("Overload 5",5); -  in console.readline (); -         } to  +         /// <summary> -         ///method overload 1: no parameter the         /// </summary> *         Static voidtest_overloaded_methods () $         {Panax NotoginsengConsole.WriteLine ("I'm the method. Overload 1: No parameter"); -         } the         /// <summary> +         ///method overload 2: A parameter that returns a value of the same type A         /// </summary> the         /// <param name= "str" ></param> +         Static voidTest_overloaded_methods (stringstr) -         { $ Console.WriteLine (str); $         } -         /// <summary> -         ///method overload 3: A parameter that returns a value of the same type the         /// </summary> -         /// <param name= "i" ></param>Wuyi         Static voidTest_overloaded_methods (inti) the         { -Console.WriteLine ("I am the method overload {0}: A parameter that is type-shaped", i); Wu         } -         /// <summary> About         ///method overloading 4:2 parameters $         /// </summary> -         /// <param name= "I" >formal parameter 1: integral type</param> -         /// <param name= "str" >formal Parameter 2: string</param> -         Static voidTest_overloaded_methods (intIstringstr) A         { +Console.WriteLine ("The integer value currently passed in is: {0}, String: {1}", I, str); the         } -         /// <summary> $         ///method overloads 5:2 parameters, compared to overloaded 4, with different parameter positions the         /// </summary> the         /// <param name= "str" >formal parameter 1: String type</param> the         /// <param name= "I" >formal parameter 2:</param> the         Static voidTest_overloaded_methods (stringStrinti) -         { inConsole.WriteLine ("The integer value currently passed in is: {0}, String: {1}", I, str); the         } the     } About}

C # method overloading

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.