What is methods?

Methods are the most basic building block you can use to organize your code. Essentially,a method is a named grouping of one or more lines of code.Ideally,each method will perform a distinct,logical task.By breaking your code down into methods, you not only simplify your life,but you also make it easier to organize your code into classes and step into the world of object oriented programming.
When you declare a method in C#,the first part of the declaration specifies the data type of the return value,and the second part indicates the method name.If your method doesn't return any information,you should use the void keyword instead of a data type at the beginning of the declaration.
Here are two examples-one method that doesn't return anything and one that does:

// This method doesn't return any information.
void MyMethodNoReturnedData()
{
// Code goes here.
}

// This method returns an integer.
int MyMethodReturnsData()
{
// Return the number 10.
return 10;
}

No comments:

Post a Comment