Chapter 5 : Method Flashcards
What are method used to?
- Break a complex program into small, manageable pieces
public partial class Form1 : Form
{
private void myButton_Click(object sender, EventArgs e)
{
Method2();
}
private void Method2()
{
Statement
}
What is the approach ( break a complex program into small, manageable pieces ) known as?
- Divide & Conquer
What is the general terms for breaking down a program to smaller units of code known as?
- Modularization
List out 2 parts for method definition
- Header
- body
Where method header appears and indicate what?
- Appears at the beginning of a method
- Indicate access mode, return type, and method name
- private void DisplayMessage() {}
What is the difference between a void method and a normal method?
- void method does not return any value to the statement that called it
What is a void method?
- A method that simply executes the statement it contains and then terminates
What is the method body?
- Is a collection of statements that are performed when the method is executed
List out the 4 parts of a method header
- Access Modifier
- Return Type
- Method Name
- Parameter ( Parentheses )
What is the access modifier? What value is available?
- Keywords that defines the access control
- Value Available
- private
- public
What is the difference between private and public method?
- Access control ( private method can be called only by code inside the same class while public class can be called by code outside the class )
What does return type specifies?
- Specifies whether or not a method returns a value
- void - no return
empty - return
What is a method name?
- The identifier of the method, it must be unique in a given program
- Like variable name
What does a method’s name always followed by?
- A pair of parentheses ()
How to create and display a method?
private void goButton_Click(object sender, EventArgs e)
{
MessageBox.Show(“This is the goButton_Click method.”);
DisplayMessage();
}
private void DisplayMessage()
{
MessageBox.Show(“This is the DisplayMessage method.”);
}
What is return point?
- A memory address that the system saves to which it should return