O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5.2. Basic console I/O

5.2.1. Writing to console

For non-GUI Java programs, you use System.out.println() to output something to the command line console. For C#, you use System.Console.WriteLine(). WriteLine is a static method of the Console class, which is found in the System namespace (see section 5.3). Both methods are similar – you can pass in a string, a numeric value, or a combination of strings and numeric values (using the + concatenation operator).

This example should make things clear.

 1: using System;
 2:
 3: class TestClass{
 4:   public static void Main(){
 5:     Console.WriteLine
 6:         ("Words\n" + "and " + 99 + " numbers.");
 7:     Console.WriteLine
 8:         ("Interesting {0} of WriteLine","usage");
 9:     Console.WriteLine 10: ("{0} plus {1} gives {2}", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required