Terminal methods to use
To get started programming, you will need to know a few methods that you can call. We want to keep things relatively simple, so we will limit ourselves to just a few methods.
To interact with the user via the terminal you will need the following using directives:
Then you will have access to the following methods. Make sure to stick with just these methods for now. You want to focus on sequence and data, and only using the language features we have covered so far. Remember this is about learning to program in general, so we will come back to explore the language libraries later.
Each line above represents a method. They all have the following structure (from left to right):
- They start with
public static
. In C# this can be called directly, which is what we are doing now. - Following this is the type it returns
void
means it returns nothing, otherwise it isstring
if it returns text data, orint
for whole numbers anddouble
for real numbers. - Next is the name of the method - for example
WriteLine
orToDouble
. - Then, in parentheses you have a list of values that are required. For
WriteLine
andWrite
you can actually pass these either a string, an integer, or a double (so we just put...
to mean there are a few options). NoticeReadLine
needs no arguments, whileToDouble
requires one string.
Example
The following code calculates a body mass index by reading the details from the user in the terminal.