Archive for the ‘D- Console Output’ Category

Console Output with Console.WriteLine

Sunday, March 8th, 2009

So, you have already used this

But for the most part of this text we will use the functionality from System.Console class to display the output of our programs

Console.WriteLine(“A string”);

prints A string, if you want to print variables

Console.WriteLine(“Var1 {0} Var2: {1} Var4: {3} Var3: {2}”, var1, var2, var3, var4);

this will print the variables within the string, notice that Var4 and Var3 are reversed in the string, the variables takes the indexes 0, 1, 2, 3… you can use {0} more than once to print variable var1 more than once.

On a relevant note, Console.WriteLine will print the string on a new string, if you do not want that you can use Console.Write in the same way