AmbitionBox

Discover Best Places to work in India

C# Programming

C# Programming Questions and Answers

Showing 1 - 10 of 10 questions

1

Which of these methods are used to read single character from the console?

a

get()

b

getline()

c

read()

d

readLine()

correct answer c

Answer: Option (C)

2

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

correct answer b

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

3

Name the exception thrown by read() on failure.

a

InterruptedException

b

SystemException

c

SystemInputException

d

I/O Exception

correct answer d

read() throws I/O exception on failure.

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

correct answer c

The stream class method writes characters to the string.

5

Which of these method used to read strings from the console?

a

get()

b

getline()

c

read()

d

readLine()

correct answer d

Answer: Option (D)

6

Name the method/methods used to read byte streams from the file?

a

ReadByte()

b

Read()

c

Readkey()

d

None of the mentioned

correct answer a,b

Answer: Option (A) and (B)

7

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

correct answer a

To read a block of bytes, use Read( ), which has this general form:
int Read(byte[ ] array, int offset, int count)

8

What would be the output for following input from the console as a character?

staticvoid 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

correct answer d

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

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

correct answer b

Byte stream uses InputStream and OutputStream classes for input and output operation.

10

What is the output returned by Console if ReadLine() stores I/O error?

a

1

b

0

c

False

d

I/O EXCEPTION ERROR

correct answer d

Answer: Option (D)

Select a company to compare with

vs

Similar Companies