Console Related:
1. Output to the console
Console.Write (value of output); Indicates that the string is written directly to the console, without wrapping , and continuing with the preceding character write.
Console.WriteLine (value of output); Represents a line break after writing a string to the console . Common
Console.WriteLine ("Output format string", variable list);
Console.Write ("Output format string", variable list);
Note: the only console.wrietline () and Console.Write () are not the former output after the newline, the latter does not wrap.
Console.WriteLine ("The wife of {0} in Deer Ding Kee has 7", Strname[0],strname[1],strname[2],strname3]);
2. Input from console
The input method provided by the console class:
Console.ReadLine (); Represents a line break after reading a string from the console . Common
This code returns a string data that can be assigned directly to a string variable, such as String Strname=console.readline ();
Sometimes you need to enter a number from the console, using the content described earlier, data conversion, such as:
int num=int. Pares (Console.ReadLine ());
int Num=convert.toint32 (Console.ReadLine ());
The above two lines of code effect the same, you can choose any one according to their own habits.
note:
console.readline () and Console.read () are completely different and cannot be mixed.
console.read (), the ASCII code for the first character of the return value
console.readline (), the return value is a string
that is, the Read method can read only the first character, and ReadLine can read more than one character and can wrap a line read
Console.readkey () function, read is from the console reading, key means to press the keyboard, then the combination of the meaning is to get the user press the function key displayed in the window, with the previous code in the window to pause the function, in the debug state, only press any key after the window will be closed.
Console.readkey Gets the next character or function key pressed by the user, and the pressed key is displayed in the console window. The console.beep plays the beep tone through the console speaker.
Console.clear Clears the display information for the console buffer and the corresponding console window.
3. Console input and output
usingSystem;usingSystem.Collection.Generic;usingSystem.Linq;usingSystem.Text;namespaceconsoletest{classconsoletest{Static voidMain (string[] args) {Console.WriteLine ("Please enter the names of two students");stringname1=console.readline ();stringName2=Console.ReadLine (); Console.WriteLine ("Please enter the score of two students");intscore1=int. Parse (Console.ReadLine ());intScore2=int. Parse (Console.ReadLine ()); Console.WriteLine ("First Student's name {0}, score {1}", Name1,score1); Console.WriteLine ("Second student's name {0}, score {1}", Name2,score2); Console.readkey ();}}}
C # Base 1:console class