C# Questions & Answers on Reading Console Input Operations for Freshers

https://www.computersprofessor.com/2018/07/c-questions-answers-on-reading-console.html
1. Name the exception thrown by read() on failure.
a) InterruptedException
b) SystemException
c) SystemInputException
d) I/O Exception
a) InterruptedException
b) SystemException
c) SystemInputException
d) I/O Exception
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()
a) get()
b) getline()
c) read()
d) readLine()
Answer: c
3. Which of these method used to read strings from the console?
3. Which of these method used to read strings from the console?
a) get()
b) getline()
c) read()
d) readLine()
b) getline()
c) read()
d) readLine()
Answer: d
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
b) StreamReader
c) StringWriter
d) None of the mentioned
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
a) Read()
b) ReadKey()
c) ReadLine()
d) All of the mentioned
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.
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
a) 1
b) 0
c) False
d) I/O EXCEPTION ERROR
Answer: d
7. What would be the output for following input from the console as a character?
static void Main(string[] args)
{
Console.WriteLine("what is your name?");
char s;
s = Convert.ToChar(Console.ReadLine());
Console.WriteLine("how are you: "+s);
Console.Read();
}
a) Compile time error
b) Code run successfully prints nothing on console
c) Code runs successfully prints input on console
d) Run time error
b) Code run successfully prints nothing on console
c) Code runs successfully prints input on console
d) Run time error
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().
8. Name the method/methods used to read byte streams from the file?
a) ReadByte()
b) Read
c) Readkey()
d) None of the mentioned
a) ReadByte()
b) Read
c) Readkey()
d) None of the mentioned
Answer: a
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
b) InputOutputStream
c) Reader
d) All of the mentioned
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()
Answer: a
Explanation: To read a block of bytes, use Read( ), which has this general form:
int Read(byte[ ] array, int offset, int count).