Programming 2 Methods
Programming 2 Methods
of a class.
project, you’ll need to indicate to the IDE which one you would like to
be the app’s entry point:
With the project open in Visual Studio, select Project > [ProjectName]
Properties... (where [ProjectName] is the name of your project).
Select the class containing the Main method that should be the entry point from
the Startup object list box.
parameter.
When program control returns from a method, that method’s
required for use in more than one method or if the app needs to save
their values between calls to the class’s methods.
The scope of a parameter declaration is the body of the method in which the
declaration appears.
The scope of a local-variable declaration is from the point at which the
declaration appears to the end of the block containing the declaration.
The scope of a non-static method, property or field of a class is the entire body of
the class.
If a local variable or parameter in a method has the same name as a
field, the field is hidden until the block terminates (scope hole).
© 2018 Pearson Education, Ltd. All
Rights Reserved.
© 2018 Pearson Education, Ltd. All Rights Reserved.
© 2018 Pearson Education, Ltd. All Rights Reserved.
© 2018 Pearson Education, Ltd. All Rights Reserved.
© 2018 Pearson Education, Ltd. All Rights Reserved.
© 2018 Pearson Education, Ltd. All Rights Reserved.
7.12 Method Overloading
Methods of the same name can be declared in the same class, or
overloaded, as long as they have different sets of parameters.
When an overloaded method is called, the C# compiler selects the
name that perform the same tasks, but on different types or numbers
of arguments.
lists and bodies, you can think of them simply as different methods.
It may help to think of the method names as “Square of int” and
int Square(int x)
double Square(int x)
The compiler generates the following error for the second Square
method:
Type 'MethodOverloadError' already defines a member called 'Square' with the
same parameter types
non-optional parameters.
bodied property.
The following reimplements the IsNoFaultState property in Fig.