C # console input and output

Source: Internet
Author: User

1. The system. Console. Write () method does not add a line break after the text is displayed, but keeps the current position on the same line. The system. Console. writeline () method will wrap.
2. The system. Console. Readline () method will be suspended.ProgramTo allow you to enter characters. Once you press enter to create a new row. The program will continue to run.

 

 
String firstname, lastname; system. Console. writeline ("Hey you! "); System. console. write ("Enter your first name:"); firstname = system. console. readline (); system. console. write ("Enter your last name:"); lastname = system. console. readline (); system. console. writeline ("your full name is {0} {1 }. ", firstname, lastname );

3. The data type returned by the system. Console. Read () method is an integer corresponding to the read character value. If no more characters are available,-1 is returned. To obtain the actual characters, you must first convert the integer into a character.

Int readvalue; char character; readvalue = system. Console. Read (); character = (char) readvalue; system. Console. writeline (character); system. Console. Readline ();

4. The system. Console. readkey () method returns the user's input after one key. It allows developers to intercept the user's key operations and execute corresponding rows. For example, you can only press the Enter key.
5. system. console. writeline ("your full name is {0} {1 }. ", firstname, lastname); {0} is the placeholder for the exchange index, and firstname is the corresponding variable.

 

 

 
If (system. console. readkey (true ). key = consolekey. enter) {system. console. readkey (true);} else {system. console. writeline ("input error! ");}

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.