Most popular web site - 224 Methods Chapter 6 29 // main entry

224 Methods Chapter 6 29 // main entry point for the application 30 [STAThread] 31 static void Main() 32 { 33 Application.Run( new MethodOverload() ); 34 } 35 36 private void showOutputButton_Click( object sender, 37 System.EventArgs e ) 38 { 39 // call both versions of Square 40 outputLabel.Text = 41 “The square of integer 7 is ” + Square( 7 ) + 42 “nThe square of double 7.5 is ” + Square ( 7.5 ); 43 } 44 45 } // end of class MethodOverload Fig. 6.18 Using overloaded methods. (Part 2 of 2.) The compiler distinguishes overloaded methods by their signatures. A method s signature is a combination of the method s name and parameter types. If the compiler looked only at method names during compilation, the code in Fig. 6.18 would be ambiguous the compiler would not know how to distinguish the two Square methods. The compiler uses overload resolution to determine which method to call. This process first searches for all the methods that can be used in the context, based on the number and type of arguments that are present. It might seem that only one method would match, but recall that C# can convert variable values to other data types implicitly. Once all matching methods are found, the closest match is chosen. This match is based on a best-fit algorithm, which analyzes the implicit conversions that will take place. Let us look at an example. In Fig. 6.18, the compiler might use the logical name Squareof int for the Square method that specifies an int parameter (line 30) and Squareof double for the Square method that specifies a double parameter (line 36). If a method Foo s definition begins as void Foo( int a, float b ) the compiler might use the logical name Foo of int and float. If the parameters are specified as void Foo( float a, int b ) the compiler might use the logical name Fooof float and int. The order of the parameters is important to the compiler; it considers the preceding two Foo methods distinct.
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

Leave a Reply