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