C# Questions & Answers – Reading Console Input Operations

This section of our 1000+ C# multiple choice questions focuses on reading console input operations in C# Programming Language.

1. Name the exception thrown by read() on failure.
a) InterruptedException
b) SystemException
c) SystemInputException
d) I/O Exception
View Answer

Answer: d
Explanation: read() throws I/O exception on failure.

2. Which of these methods are used to read single character from the console?
a) get()
b) getline()
c) read()
d) readLine()
View Answer

Answer: c
Explanation: None.

3. Which of these method used to read strings from the console?
a) get()
b) getline()
c) read()
d) readLine()
View Answer

Answer: d
Explanation: None.
advertisement
advertisement

4. Which among the following methods are used to write characters to a string?
a) StreamWriter
b) StreamReader
c) StringWriter
d) None of the mentioned
View Answer

Answer: c
Explanation: The stream class method writes characters to the string.

5. Which method in Console enables to read individual inputs directly from the keyboard in a non line buffered manner?
a) Read()
b) ReadKey()
c) ReadLine()
d) All of the mentioned
View Answer

Answer: b
Explanation: The .NET Framework includes a method in Console that enables you to read individual keystrokes directly from the keyboard, in a non-line-buffered manner. This method is called ReadKey(). When it is called, it waits until a key is pressed. When the key is pressed, ReadKey( ) returns the keystroke immediately.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. What is the output returned by Console if ReadLine() stores I/O error?
a) 1
b) 0
c) False
d) I/O EXCEPTION ERROR
View Answer

Answer: d
Explanation: None.

7. What will be the output for following input from the console as a character?

advertisement
  1.  static void Main(string[] args)
  2.  {
  3.      Console.WriteLine("what is your name?");
  4.      char s;
  5.      s = Convert.ToChar(Console.ReadLine());
  6.      Console.WriteLine("how are you: "+s);
  7.      Console.Read();
  8.  }

a) Compile time error
b) Code run successfully prints nothing on console
c) Code runs successfully prints input on console
d) Run time error
View Answer

Answer: d
Explanation: Since only a single character is required to be entered on console when a string is entered, a run time exception is being generated as we had not used Read() which reads single character but used readLine() which reads string and is converted into the char using convert.tochar().
advertisement

8. Name the method/methods used to read byte streams from the file?
a) ReadByte()
b) Read
c) Readkey()
d) None of the mentioned
View Answer

Answer: a
Explanation: None.

9. Which of these classes are used by Byte streams for input and output operation?
a) InputStream
b) InputOutputStream
c) Reader
d) All of the mentioned
View Answer

Answer: b
Explanation: Byte stream uses InputStream and OutputStream classes for input and output operation.

10. Which of these method/methods are used to read block or array of bytes from the file?
a) Read()
b) ReadByte()
c) ReadLine()
d) Readkey()
View Answer

Answer: a
Explanation: To read a block of bytes, use Read( ), which has this general form:
int Read(byte[ ] array, int offset, int count).

Sanfoundry Global Education & Learning Series – C# Programming Language.

To practice all areas of C# language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.