Working with methods and tuples
Methods are members of a type that execute a block of statements. They are functions that belong to a type.
Returning values from methods
Methods can return a single value or nothing:
- A method that performs some actions but does not return a value indicates this with the
void
type before the name of the method. - A method that performs some actions and returns a value indicates this with the type of the return value before the name of the method.
For example, in the next task, you will create two methods:
WriteToConsole
: This will perform an action (writing some text to the console), but it will return nothing from the method, indicated by thevoid
keyword.GetOrigin
: This will return a text value, indicated by thestring
keyword.
Let's write the code:
- In
Person.cs
, add statements to define the two methods that I described earlier, as shown in the following code:
#region Methods: Actions the type can perform.
public void WriteToConsole()
{
...