First try the most basic Hello world!
Using system;using system.collections.generic;using system.linq;using system.text;using System.threading.tasks;namespace consoleapplication2{class program {static void Main (string[] args) { System.Console.WriteLine ("Hello world!" ); System.Console.ReadLine (); } }}
The ReadLine function is because my console does not appear to press any key to exit, so manually fill a readline to see the results (prevent the console from flashing directly)
Then we tested the backgroundcolor and foregroundcolor about the color.
Using system;using system.collections.generic;using system.linq;using system.text;using System.threading.tasks;namespace consoleapplication2{class program {static void Main (string[] args) { System.Console.BackgroundColor = Consolecolor.green; System.Console.ForegroundColor = consolecolor.darkred; System.Console.WriteLine ("Hello world!" ); System.Console.ReadLine (); } }}
Effect:
And then try another one. Implement output Hello world!
Using system;using system.collections.generic;using system.linq;using system.text;using System.threading.tasks;namespace consoleapplication2{class program {static void Main (string[] args) { Class1 HelloWorld = new
CLASS1:
Using system;using system.collections.generic;using system.linq;using system.text;using System.threading.tasks;namespace consoleapplication2{class Class1 {public void Hello () { Console.WriteLine ("Hello World from class1!" ); } }}
If you change the Hello function to a static type, you can call it without instantiating it.
As follows
Main
Using system;using system.collections.generic;using system.linq;using system.text;using System.threading.tasks;namespace consoleapplication2{class program {static void Main (string[] args) { Class1.hello (); System.Console.ReadLine (); } }}
CLASS1:
Using system;using system.collections.generic;using system.linq;using system.text;using System.threading.tasks;namespace consoleapplication2{class Class1 {public static void Hello () {Console . WriteLine ("Hello World from class1!" ); } }}
Try using the console's parameters
Setting content:
Code:
Using system;using system.collections.generic;using system.linq;using system.text;using System.threading.tasks;namespace consoleapplication2{class program {static void Main (string[] args) { System.Console.WriteLine (Args[0] + "" + args[1]); System.Console.ReadLine (); } }}
Run results
C + + Hello World