Users Online

· Guests Online: 47

· 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 ? Introduction of Console I/O Operations

C# Questions & Answers – Introduction of Console I/O Operations

 

 

 

This set of C# Questions and Answers for Campus interviews focuses on “Introduction of Console I/O operations”.

 

 

 

 

1. Which of the classes provide the operation of reading from and writing to the console in C#.NET?
a) System.Array
b) System.Output
c) System.ReadLine
d) System.Console

Answer: d
Explanation: The method for reading and writing to the console in C#.NET is provided by System.Console class. This class gives us access to the standard input, output and standard error streams.

 

 

 

2. Which of the given stream methods provide access to the output console by default in C#.NET?
a) Console.In
b) Console.Out
c) Console.Error
d) All of the mentioned

Answer: b
Explanation: The standard output stream Console.Out sends output to the screen by default.

 

 

 

 

3. Which of the given stream methods provide access to the input console in C#.NET?
a) Console.Out
b) Console.Error
c) Console.In
d) All of the mentioned

Answer: c
Explanation: Console.In is an instance of TextReader, and we can use the methods and properties defined by TextReader to access it to read the input from the keyboard.
 

 

 

 

4. The number of input methods defined by the stream method Console.In in C#.NET is?
a) 4
b) 3
c) 2
d) 1

Answer: b
Explanation: Two basic methods : read() and readline() and third method readkey() introduced in .NET FrameWork 2.0.

 

 

 

 

5. Select the correct methodS provided by Console.In?
a) Read(), ReadLine()
b) ReadKey(), ReadLine()
c) Read(), ReadLine(), ReadKey()
d) ReadKey(), ReadLine()

Answer: c
Explanation: The two method Read() and ReadLine() available in .NET Framework 1.0 and Third method ReadKey() was added by .NET Framework 2.0.

 

 

 

 

6. Choose the output returned when read() reads the character from the console?
a) String
b) Char
c) Integer
d) Boolean

Answer: c
Explanation: Read() returns the character read from the console. It returns the result. The character is returned as an int, which should be cast to char.

 

 

 

 

7. Choose the output returned when an error condition is generated while read() reads from the console.
a) False
b) 0
c) -1
d) All of the mentioned

Answer: c
Explanation: Read() returns –1 on error. This method also throws an IOException on failure.

 

 

 

8. Choose the object of TextReader class.
a) Console.In
b) Console.Out
c) Console.Error
d) None of the mentioned

Answer: a
Explanation: Console.In is an instance(object) of TextReader class and we can use the methods and properties defined by TextReader to invoke the object console.in.

 

 

 

 

9. Choose the object/objects defined by the Textwriter class.
a) Console.In
b) Console
c) Console.Error
d) None of the mentioned

Answer: c
Explanation: Console.Out and Console.Error are objects of type TextWriter class.

 

 

 

 

 

10. What will be the output of the following C# code?

  1.  static void Main(string[] args)
  2.  {
  3.      int a = 10, b = 0;
  4.      int result;
  5.      Console.Out.WriteLine("This will generate an exception.");
  6.      try
  7.      {
  8.          result = a / b; // generate an exception
  9.      }
  10.      catch (DivideByZeroException exc)
  11.      {
  12.          Console.Error.WriteLine(exc.Message);
  13.      }
  14.      Console.ReadLine();
  15.  }

a) This will generate an exception
b) 0
c) Compile time error
d)

This will generate an exception
Attempted to Divide by Zero

 

Answer: d
Explanation: None.

 

 

 

 

11. Choose the methods provided by Console.Out and Console.Error?
a) Write
b) WriteLine
c) WriteKey
d) Write & WriteLine

Answer: d
Explanation: None.

 

 

 

 

 

12. What will be the output of the following C# code?

  1.  static void Main(string[] args)
  2.  {
  3.      Console.WriteLine("This is a Console Application:");
  4.      Console.Write("Please enter your lucky number:");
  5.      string val1 = Console.ReadLine();
  6.      int val2 = System.Convert.ToInt32(val1, 10);
  7.      val2 = val2 * val2;
  8.      Console.WriteLine("square of number is:" +val2);
  9.      Console.Read();
  10.  }

a) Compile time error
b) Runs successfully does not print anything
c) Runs successfully, ask for input and hence displays the result
d) Syntax Error

Answer: c
Explanation: None.
Output : This is a Console Application:
Please enter your lucky number: 3
Square of number is : 9

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.77 seconds
10,841,158 unique visits