Console

A cosole application is a program that can only display text output.


The main() method is the entry point for every C# console application.
The main method can be defined in any valid class


static void Main(string[] args) 
{
   System.Console.WriteLine("some text")
   System.Console.WriteLine("some text {0} some text","parameter 1")
   System.Console.Write("hello")
}


The last line should be Console.ReadLine() - this causes the program to pause and display any results



WriteLine - displays a line of text followed by a carriage return
Write - displays a line of text
ReadLine - pauses the program to wait for input and the Enter key to be pressed


use {0} to indicate a placeholder for the first variable's value


Select (Debug > Start) then the command window is automatically closed after the program finishes
Select (Debug > Start with Debugging) will leave the command window open to allow you to view the programs output.


You can display multiple lines by using the newline character ("\n")


If Console.WriteLine does not receive a text string then it will output a newline character.


Escape Characters

\n - newline, positions the cursor at the beginning of the next line
\t - horizontal tab, moves he cursor to the next tab stop
\r - carriage return, positions the cursor at the start of the current line ?
\\ backslash, prints a backslash character
\* double quote, prints a double quote character





© 2017 Better Solutions Limited. All Rights Reserved. © 2017 Better Solutions Limited

Top

PrevNext