Users Online

· Guests Online: 104

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Questions & Answers ? Reading Console Input Operations

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

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()

Answer: c
Explanation: None.

 

 

 

 

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

Answer: d
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

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

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

Answer: d
Explanation: None.

 

 

 

 

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

  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

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

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

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).

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.85 seconds
10,830,716 unique visits