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
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
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
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
5. Select the correct methodS provided by Console.In?
a) Read(), ReadLine()
b) ReadKey(), ReadLine()
c) Read(), ReadLine(), ReadKey()
d) ReadKey(), ReadLine()
6. Choose the output returned when read() reads the character from the console?
a) String
b) Char
c) Integer
d) Boolean
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
8. Choose the object of TextReader class.
a) Console.In
b) Console.Out
c) Console.Error
d) None of the mentioned
9. Choose the object/objects defined by the Textwriter class.
a) Console.In
b) Console
c) Console.Error
d) None of the mentioned
10. What will be the output of the following C# code?
static void Main(string[] args)
{
int a = 10, b = 0;
int result;
Console.Out.WriteLine("This will generate an exception.");
try
{
result = a / b; // generate an exception
}
catch (DivideByZeroException exc)
{
Console.Error.WriteLine(exc.Message);
}
Console.ReadLine();
}
a) This will generate an exception
b) 0
c) Compile time error
d)
This will generate an exception Attempted to Divide by Zero
11. Choose the methods provided by Console.Out and Console.Error?
a) Write
b) WriteLine
c) WriteKey
d) Write & WriteLine
12. What will be the output of the following C# code?
static void Main(string[] args)
{
Console.WriteLine("This is a Console Application:");
Console.Write("Please enter your lucky number:");
string val1 = Console.ReadLine();
int val2 = System.Convert.ToInt32(val1, 10);
val2 = val2 * val2;
Console.WriteLine("square of number is:" +val2);
Console.Read();
}
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