0
what method please give me some examples thanks.
2 Answers
+ 2
I assume your question is "What is a method?"... If so, think about it as a verb in your program. They are the blocks of code that will perform actions in your code. Some examples are things you do in real life: Sum(), Divide(), Walk(), Snore(), Drink(). See? They are all verbs... Now, lets get more technical. Lets implement the method Sum().
This is the syntax to follow when creating a Verb/Method/Function/Sub-Routine, etc: ignore the +
return type + name + ( )
{
//Here is where you code the action of the method...
}
ok, so our method will return an integer, i want the sum of 2 numbers to return to me a variable called result of type integer. The two numbers are called parameters and you have to declare them inside the parenthesis.
Lets code:
int Sum(int num1, int num2)
{
int result = num1 + num2;
}
That was the implementation of the method Sum(). I hope you learned the basics of methods. Ask if you dont understand anything else. Happy coding!
0
thanks so much.