Read () will not be processed until enter, that is, when querying, if you enter t and then enter, you actually enter three characters. They are the characters X, carriage return (13) and line feed (10). Of course there will be mistakes.
The text is as follows:
Console input and output:
Output:
1, system. Console.WriteLine("Hello World!" );
2. Use the system; Console. WriteLine("Hello World!" )。
Input:
1, system. console . ReadLine(); /Read a line.
2、? System. console . Read(); /Read a character.
Console input:
The Read () and ReadLine0 methods of the system. Console classes can be used to implement console input. This paper introduces in detail how to use these two methods to obtain input:
1, console. Read) method.
The ReadO method reads one character at a time from the input stream (console) and does not return until the Enter key is received. Returns the received character as an int (32-bit integer) value to the variable; If there is no data in the input stream,-1 is returned.
The ReadO method is a static method, which we can call directly through the class name console. The calling format is Console.Read, and the prototype of the ReadO method is: public static int Read ().
If we Enter multiple characters and then press Enter (the input stream will contain the characters entered by the user, plus the Enter key and the newline \r\n'), the Read () method will only return the first character entered by the user. But we can call the Read () method many times through the loop control of the program to get all the input characters.
The data type returned by the ReadO method to the variable is a 32-bit integer. If you need to get the input characters, you must explicitly convert the data type to get the corresponding characters.
Examples are as follows:
2, the console. ReadLine) method
ReadLine) method is used to read a string from the console one line at a time, and does not return the read string until the Enter key is met. However, the string does not contain the Enter key and the line break (\r\n'). If no input is received, or invalid input is received, the ReadLine) method will return null.
ReadLine) method is also a static method, which can be directly called through the class name Console, and the calling format is Console.ReadLine.
The prototype of ReadLine method is: public static string ReadLine).
Examples are as follows:
Extended data:
Output in string format:
//public static void Main ()
{
Console. WriteLine ("Align left in space with width: {0,-10}", 99);
Console. WriteLine ("Align right in a space with width: {0, 10]}", 99);
Console. WriteLine ("Align left in the space with width: {0,-10}," LLL ");
Console. WriteLine ("Align to the right in the space with the width of {0, 10} and" RRR ");
Console. WriteLine(" Currency-{ 0:c } { 1:C4 } ",88.8,-888.8);
Console. WriteLine(" 10 decimal integer -{0: d5} ",88);
Console. WriteLine ("Scientific Counting -{0: e}", 888.8);
Console. WriteLine ("fixed decimal point -{0: F3}", 888.8888);
Console. WriteLine ("floating point number -{0: g}", 888.8888);
Console. WriteLine ("number format -{0: n}", 8888888.8);
Console. WriteLine(" 16 hexadecimal format -{0: x4]} ",88); Console. ReadLine);
}
Format specifier:
References:
Baidu encyclopedia -c#