About console usage in C #

Source: Internet
Author: User

Console.Write indicates that the string is written directly to the console, without wrapping, and continuing with the previous character write.
Console.WriteLine represents a line break after writing a string to the console.
The console.read indicates that the string is read from the console and does not wrap.
Console.ReadLine indicates that a string is wrapped after it is read from the console.
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.

Output to console

The output to the console is to output the data to the console and display it. The NET Framework provides the console class to implement this task, with the following output:

Console.WriteLine ();
Console.Write ();
Console.WriteLine (value of output);
Console.Write (value of output);
Console.WriteLine ("Output format string", variable list);
Console.Write ("Output format string", variable list);


Console.WriteLine ("This was {0}, this is {1} and {2}", Strname[0],strname[1],strname [2],strname3]);

This method contains two parameters: the format string and the variable list. "This was {0}, this is {1} and {2}" it is a format string, {0}, {1}, {2} is called a placeholder, represents a variable table that is followed sequentially, 0 corresponds to the first variable in the list of variables, 1 corresponds to the 2nd variable of the variable list, and so on, completes the output.

Input from console

The input from the console is the input of data from the console to the program.

The input method provided by the console class:

Console.ReadLine (); 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. Parse (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.

Attention:

The input results of console.readline () and Console.read () are completely different and cannot be mixed.
Console.read (), the ASCII code that returns the first character of the value

Console.ReadLine (), the return value is a string.

That is, the Read method can only read the first character, and ReadLine can read more than one character and can be read as a newline.

The role of Console.readkey ():

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

The window does not close after any key

About console usage in C #

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.