Most application require some input from the user and give output as a result. To display text to the console window you use the Console.Write or Console.WriteLine method.
The difference between these two is that Console.WriteLine is followed by a line terminator, which moves the cursor to the next line after the text output. The program below will display hello world! to the console window:
The difference between these two is that Console.WriteLine is followed by a line terminator, which moves the cursor to the next line after the text output. The program below will display hello world! to the console window:
Note : the parentheses after the WriteLine method. This is the way to pass data, or arguments, to methods. In our case WriteLine is the method and we pass "Hello World!" to it as an argument. String arguments must be enclosed in quotation marks.
DISPLAYING OUTPUT
We can display variable values to the console window:
To display a formatted string, use the following syntax :
As you can see, the value of x replaced {0} and the value of y replaced {1}. You can have as many variable placeholders as yo need. (i.e.:{3}, {4}, etc.).
Next : C# series 1.7 : Getting User Input
Next : C# series 1.7 : Getting User Input
No comments:
Post a Comment