C # Note (1)-console. Read () and console. Readline () Functions

Source: Internet
Author: User

Note: Here are some of my notes, problems, and solutions in the process of learning c. If you have time to write them down, it may be trivial and not systematic, but I think some people may encounter the same problem and find a solution everywhere. If you can help me, I will be very happy.

I will only talk about one problem in each article, and try to clear the cause and solution as much as possible. Due to the limited level, I cannot guarantee that everything is correct. If there are any mistakes, thank you for your criticism.

 

The Console. Read () function reads one character and returns the int type;
The Console. ReadLine () function reads a line of characters and returns the string type.

The prototype is as follows:
Public static int Read ();
The next character in the input stream. If no more characters are available for reading, the value is minus one (-1 ).
Public: static String ^ ReadLine ()
The next line of Characters in the input stream. If there are no more available lines, it is a null reference (Nothing in Visual Basic ).

The following code cannot be compiled:
String name;
Name = Console. Read ();
Error: error CS0029: The type "int" cannot be converted to "string"

In this way, you can:
String name;
Name = Console. ReadLine ();

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.