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
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
Explanation: None.
3. Which of these method used to read strings from the console?
a) get()
b) getline()
c) read()
d) readLine()
View Answer
Explanation: None.
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
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
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
View Answer
Explanation: None.
7. What will 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
View Answer
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
View Answer
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
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
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.
- Apply for Computer Science Internship
- Check C# Books
- Practice Computer Science MCQs
- Check Computer Science Books
- Practice MCA MCQs