Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Which of the following is used to perform all input & output operations in C#?(a) streams(b) Variables(c) classes(d) MethodsI had been asked this question in my homework.Query is from Character Stream topic in division Console I/O Operations and Stream Classes of C#

Answer» CORRECT option is (a) streams

The best explanation: Streams are used for INPUT and output operations in any PROGRAMMING language.
2.

Which method among the following returns the integer if no character is available?(a) int peek()(b) int read()(c) string ReadLine()(d) none of the mentionedI have been asked this question in an internship interview.My question is from Character Stream in division Console I/O Operations and Stream Classes of C#

Answer»

The correct CHOICE is (a) int peek()

The best EXPLANATION: OBTAINS the next character from the input STREAM, but does not remove that character. RETURNS –1 if no character is available.

3.

Which method of character stream class returns the numbers of characters successfully read starting at count?(a) int Read()(b) int Read(char[] buffer, int index, int count)(c) int ReadBlock(char[ ] buffer, int index, int count)(d) none of the mentionedThis question was addressed to me in my homework.My question comes from Character Stream topic in portion Console I/O Operations and Stream Classes of C#

Answer»

The CORRECT answer is (B) int Read(char[] BUFFER, int index, int count)

The explanation is: Attempts to read the count characters into buffer starting at buffer[count], returning the number of characters successfully read.

4.

Which method of the character stream class returns the numbers of characters successfully read starting at index?(a) int Read()(b) int Read(char[] buffer, int index, int count)(c) int ReadBlock(char[ ] buffer, int index, int count)(d) none of the mentionedThis question was posed to me in semester exam.This is a very interesting question from Character Stream topic in chapter Console I/O Operations and Stream Classes of C#

Answer»

The CORRECT ANSWER is (C) int ReadBlock(char[ ] buffer, int INDEX, int count)

To explain: Attempts to read the count characters into buffer starting at buffer[index], returning the number of characters SUCCESSFULLY read.

5.

Which of these is a method used to clear all the data present in output buffers?(a) clear()(b) flush()(c) fflush()(d) close()I had been asked this question in homework.My question comes from Character Stream in chapter Console I/O Operations and Stream Classes of C#

Answer» CORRECT ANSWER is (b) flush()

The EXPLANATION is: None.
6.

Which among the following classes are used to perform the character based file operations?(a) StreamReader(b) InputReaderWriter(c) OutputStream(d) All of the mentionedThis question was posed to me in unit test.This intriguing question comes from Character Stream in chapter Console I/O Operations and Stream Classes of C#

Answer»

The CORRECT option is (a) StreamReader

For explanation: In general, to perform character-based file operations, wrap a FILESTREAM inside a StreamReader or a STREAMWRITER. These classes automatically CONVERT a byte STREAM into a character stream, and vice versa.

7.

The advantages of using character stream based file handling are?(a) they operate directly on unicode characters(b) they operate directly on bits(c) they store unicode text(d) all of the mentionedI got this question in an online quiz.Origin of the question is Character Stream topic in section Console I/O Operations and Stream Classes of C#

Answer»

Right answer is (a) they OPERATE directly on unicode characters

To explain I WOULD say: Although byte-oriented file HANDLING is quite common, it is possible to use character-based streams for this purpose. The advantage of the character streams is that they operate directly on Unicode characters. THUS, if you want to store Unicode text, the character streams are CERTAINLY the best option.

8.

From which of these classes, the character based output stream class Stream Writer is derived?(a) TextWriter(b) TextReader(c) Character Stream(d) All of the mentionedThe question was asked in exam.This key question is from Character Stream in division Console I/O Operations and Stream Classes of C#

Answer»

The correct CHOICE is (a) TEXTWRITER

Easiest explanation - STREAMWRITER is DERIVED from TextWriter. To create a character-based output stream, WRAP a Stream object (such as a FileStream) inside a StreamWriter.

9.

Which of these is a method used to clear all the data present in output buffers?(a) clear()(b) flush()(c) fflush()(d) close()I have been asked this question during an interview.The doubt is from Byte Stream in portion Console I/O Operations and Stream Classes of C#

Answer»

The correct ANSWER is (b) FLUSH()

Easiest EXPLANATION - NONE.

10.

Choose the filemode method which is used to create a new output file with the condition that the file with same name if exists will destroy the old file:(a) FileMode.CreateNew(b) FileMode.Create(c) FileMode.OpenOrCreate(d) FileMode.TruncateThis question was addressed to me at a job interview.This is a very interesting question from Byte Stream topic in division Console I/O Operations and Stream Classes of C#

Answer»

The CORRECT CHOICE is (b) FileMode.Create

The EXPLANATION: CREATES a new output FILE. Any pre-existing file with the same name will be destroyed.

11.

Choose the filemode method which is used to create a new output file with the condition that the file with same name must not exist.(a) FileMode.CreateNew(b) FileMode.Create(c) FileMode.OpenOrCreate(d) FileMode.TruncateThis question was addressed to me in final exam.Query is from Byte Stream in portion Console I/O Operations and Stream Classes of C#

Answer»

Correct option is (a) FileMode.CreateNew

The EXPLANATION: CREATES a new OUTPUT file. The file must not already be EXISTING.

12.

Which property among the following represents the current position of the stream?(a) long Length(b) long Position(c) int Length(d) all of the mentionedThe question was asked in my homework.Question is taken from Byte Stream in section Console I/O Operations and Stream Classes of C#

Answer»

The correct ANSWER is (a) long LENGTH

Best explanation: This PROPERTY contains the length of the STREAM. This property is read-only.

13.

Which among the following is used for storage of unmanaged memory aspects?(a) BufferedStream(b) FileStream(c) MemoryStream(d) UnmanagedMemoryStreamThe question was posed to me in an interview.Asked question is from Byte Stream in division Console I/O Operations and Stream Classes of C#

Answer»

Correct option is (d) UnmanagedMemoryStream

Easy explanation - A byte STREAM that USES UNMANAGED MEMORY for storage.

14.

Which among the following is used for storage of memory aspects?(a) BufferedStream(b) FileStream(c) MemoryStream(d) None of the mentionedThe question was posed to me by my college director while I was bunking the class.My enquiry is from Byte Stream in chapter Console I/O Operations and Stream Classes of C#

Answer»

Right CHOICE is (C) MemoryStream

To explain: A byte STREAM that USES memory for STORAGE.

15.

Which of these classes is used for input and output operation when working with bytes?(a) InputStream(b) Reader(c) Writer(d) All of the mentionedI have been asked this question during an interview.The query is from Byte Stream topic in chapter Console I/O Operations and Stream Classes of C#

Answer»

Correct CHOICE is (a) INPUTSTREAM

To explain I WOULD say: InputStream & OutputStream are designed for byte stream. READER and writer are designed for character stream.

16.

Which of these data types is returned by every method of OutputStream?(a) int(b) float(c) byte(d) none of the mentionedI have been asked this question by my college director while I was bunking the class.The origin of the question is Byte Stream in portion Console I/O Operations and Stream Classes of C#

Answer»

Correct OPTION is (d) NONE of the mentioned

To EXPLAIN I would say: Every METHOD of OutputStream RETURNS void and throws an IOExeption in case of errors.

17.

Which of these classes is used to read and write bytes in a file?(a) FileReader(b) FileWriter(c) FileInputStream(d) InputStreamReaderI had been asked this question during an interview for a job.This question is from Byte Stream topic in division Console I/O Operations and Stream Classes of C#

Answer» CORRECT CHOICE is (C) FileInputStream

Explanation: NONE.
18.

Select the action of the method long seek()?(a) Attempts to readup to count bytes into buffer starting at buffer[offset](b) Writes a single byte to an output stream(c) Sets the current position in the stream to the specified offset from specified origin and hence returns the new position(d) None of the mentionedI have been asked this question in final exam.I want to ask this question from Introduction of Stream Classes in portion Console I/O Operations and Stream Classes of C#

Answer»

The CORRECT ANSWER is (c) Sets the current position in the stream to the SPECIFIED offset from specified origin and HENCE returns the new position

To explain I would say: LONG Seek(long offset, SeekOrigin origin)

Sets the current position in the stream to the specified offset from the specified origin. It returns the new position.

19.

Select the statements which define the stream.(a) A stream is an abstraction that produces or consumes information(b) A stream is linked to a physical device by the I/0 system(c) C# programs perform I/O through streams(d) All of the mentionedThe question was asked in a national level competition.This is a very interesting question from Introduction of Stream Classes in chapter Console I/O Operations and Stream Classes of C#

Answer» CORRECT ANSWER is (d) All of the mentioned

The EXPLANATION is: NONE.
20.

Name the method which returns integer as -1 when the end of file is encountered.(a) int read()(b) int ReadByte()(c) void readbyte()(d) none of the mentionedThe question was asked during an interview.The origin of the question is Introduction of Stream Classes topic in section Console I/O Operations and Stream Classes of C#

Answer»

The correct option is (b) int ReadByte()

Easy EXPLANATION - Returns an integer representation of the next available BYTE of input. Returns –1 when the end of the FILE is ENCOUNTERED.

21.

Select the method which returns the number of bytes from the array buffer:(a) void WriteByte(byte value)(b) int Write(byte[] buffer, int offset, int count)(c) write()(d) none of the mentionedI had been asked this question in class test.The origin of the question is Introduction of Stream Classes topic in division Console I/O Operations and Stream Classes of C#

Answer» CORRECT option is (b) int Write(byte[] buffer, int offset, int count)

Best explanation: Writes a subrange of count bytes from the ARRAY buffer, beginning at buffer[offset], RETURNING the NUMBER of bytes written.
22.

Select the method which returns the number of bytes from the array buffer:(a) void WriteByte(byte value)(b) int Write(byte[] buffer, int offset, int count)(c) write()(d) none of the mentionedI got this question in semester exam.Query is from Introduction of Stream Classes topic in division Console I/O Operations and Stream Classes of C#

Answer»
23.

Select the method which writes the contents of the stream to the physical device.(a) fflush()(b) void fflush()(c) void Flush()(d) flush()This question was posed to me during an interview for a job.I would like to ask this question from Introduction of Stream Classes topic in portion Console I/O Operations and Stream Classes of C#

Answer»

Correct ANSWER is (c) void FLUSH()

EASIEST explanation - The method used to write the contents of the stream to the PHYSICAL device.

24.

The method used to write a single byte to an output stream?(a) void WriteByte(byte value)(b) int Write(byte[] buffer ,int offset ,int count)(c) write()(d) none of the mentionedThis question was posed to me in an online quiz.My question comes from Introduction of Stream Classes in section Console I/O Operations and Stream Classes of C#

Answer» RIGHT CHOICE is (a) void WriteByte(byte value)

The EXPLANATION is: Writes a SINGLE byte to an OUTPUT stream.
25.

Choose the stream class method which is used to close the connection?(a) close()(b) static close()(c) void close()(d) none of the mentionedI got this question during an interview.The doubt is from Introduction of Stream Classes topic in portion Console I/O Operations and Stream Classes of C#

Answer»

Correct option is (C) void close()

The BEST I can explain: void close() CLOSES the STREAM.

26.

Choose the class on which all stream classes are defined?(a) System.IO.stream(b) Sytem.Input.stream(c) System.Output.stream(d) All of the mentionedThe question was posed to me in homework.This key question is from Introduction of Stream Classes in portion Console I/O Operations and Stream Classes of C#

Answer»

Correct answer is (a) System.IO.stream

The best explanation: The core stream class is System.IO.Stream. Stream represents a BYTE stream and is a base class for all other stream classes. It is also ABSTRACT, which MEANS that you cannot instantiate a Stream object. Stream DEFINES a set of STANDARD stream operations.

27.

Select the namespace on which the stream classes are defined?(a) System.IO(b) System.Input(c) System.Output(d) All of the mentionedThe question was asked by my college professor while I was bunking the class.The question is from Introduction of Stream Classes in section Console I/O Operations and Stream Classes of C#

Answer»

The correct ANSWER is (a) System.IO

To EXPLAIN: The core STREAM classes are defined within the System.IO namespace. To use these classes, you will usually include the following STATEMENT near the top of your program: using System.IO;

28.

Select the namespace/namespaces which consists of methods like Length(), Indexer(), Append() for manipulating the strings.(a) System.Class(b) System.Array(c) System.Text(d) None of the mentionedI got this question during an interview for a job.The question is from Writing Console Output Operations topic in section Console I/O Operations and Stream Classes of C#

Answer»

The correct OPTION is (c) System.Text

Explanation: The system.text NAMESPACE CONTAINS the Stringbuilder class and hence MUST include USING system.text for manipulating the mutable strings.

29.

Which of these classes is used to create an object whose character sequence is mutable?(a) String()(b) StringBuilder()(c) String() & StringBuilder()(d) None of the mentionedThe question was posed to me during an interview.My question is from Writing Console Output Operations in section Console I/O Operations and Stream Classes of C#

Answer»

Right answer is (b) StringBuilder()

Easiest EXPLANATION - MUTABLE STRINGS are dynamic strings. They can GROW dynamically as characters are added to them. stringbuilder class supports those METHODS that are useful for manipulating dynamic strings.

30.

Which of the following statement is correct?(a) reverse() method reverses some characters(b) reverseall() method reverses all characters(c) replace() method replaces all instances ofa character with new character(d) replace() method replaces first occurrence of a character in invoking string with another characterThis question was posed to me in examination.The doubt is from Writing Console Output Operations in chapter Console I/O Operations and Stream Classes of C#

Answer»

The CORRECT OPTION is (c) replace() method replaces all instances ofa character with NEW character

Explanation: REVERSE() and replace() are by definition.

31.

Choose the correct statement about the WriteLine()?(a) Can display one or more value to the screen(b) Adds a newline character at the end of the each new output(c) Allows to output data in as many different formats(d) All of the mentionedThis question was addressed to me by my college director while I was bunking the class.This key question is from Writing Console Output Operations in division Console I/O Operations and Stream Classes of C#

Answer» CORRECT CHOICE is (d) All of the mentioned

Easiest EXPLANATION - By the DEFINITION of WRITELINE().
32.

Which of these classes are used by Byte streams for input and output operation?(a) InputStream(b) InputOutputStream(c) Reader(d) All of the mentionedThe question was asked in an interview for internship.My question is taken from Reading Console Input Operations in division Console I/O Operations and Stream Classes of C#

Answer»

Right answer is (b) InputOutputStream

For explanation: BYTE STREAM uses INPUTSTREAM and OutputStream classes for INPUT and output operation.

33.

Name the method/methods used to read byte streams from the file?(a) ReadByte()(b) Read(c) Readkey()(d) None of the mentionedThe question was asked by my college professor while I was bunking the class.Question is from Reading Console Input Operations in section Console I/O Operations and Stream Classes of C#

Answer»

The CORRECT ANSWER is (a) ReadByte()

EASIEST EXPLANATION - NONE.

34.

What is the output returned by Console if ReadLine() stores I/O error?(a) 1(b) 0(c) False(d) I/O EXCEPTION ERRORI have been asked this question in homework.My question is from Reading Console Input Operations topic in section Console I/O Operations and Stream Classes of C#

Answer»

The CORRECT ANSWER is (d) I/O EXCEPTION ERROR

The BEST I can explain: None.

35.

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 mentionedThis question was posed to me in a national level competition.This intriguing question originated from Reading Console Input Operations in division Console I/O Operations and Stream Classes of C#

Answer»

The correct option is (b) ReadKey()

To EXPLAIN I would say: 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.

36.

Which among the following methods are used to write characters to a string?(a) StreamWriter(b) StreamReader(c) StringWriter(d) None of the mentionedThe question was asked in unit test.This interesting question is from Reading Console Input Operations topic in section Console I/O Operations and Stream Classes of C#

Answer»

The CORRECT CHOICE is (C) StringWriter

Best explanation: The STREAM class method writes characters to the STRING.

37.

Which of these method used to read strings from the console?(a) get()(b) getline()(c) read()(d) readLine()This question was addressed to me in unit test.I'd like to ask this question from Reading Console Input Operations topic in section Console I/O Operations and Stream Classes of C#

Answer» CORRECT ANSWER is (d) READLINE()

Best EXPLANATION: None.
38.

Which of these methods are used to read single character from the console?(a) get()(b) getline()(c) read()(d) readLine()The question was posed to me by my school teacher while I was bunking the class.My question comes from Reading Console Input Operations topic in section Console I/O Operations and Stream Classes of C#

Answer» RIGHT answer is (C) READ()

EASY explanation - NONE.
39.

Name the exception thrown by read() on failure.(a) InterruptedException(b) SystemException(c) SystemInputException(d) I/O ExceptionThis question was addressed to me in quiz.Question is from Reading Console Input Operations in division Console I/O Operations and Stream Classes of C#

Answer» CORRECT ANSWER is (d) I/O EXCEPTION

Explanation: READ() THROWS I/O exception on failure.
40.

Choose the object of TextReader class.(a) Console.In(b) Console.Out(c) Console.Error(d) None of the mentionedThe question was asked in class test.I need to ask this question from Introduction of Console I/O Operations in portion Console I/O Operations and Stream Classes of C#

Answer»

Correct CHOICE is (a) Console.In

The BEST I can explain: 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.

41.

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 mentionedThe question was asked in my homework.Question is from Introduction of Console I/O Operations topic in section Console I/O Operations and Stream Classes of C#

Answer»

Right OPTION is (c) -1

To explain I would say: READ() RETURNS –1 on ERROR. This method also throws an IOEXCEPTION on failure.

42.

Choose the output returned when read() reads the character from the console?(a) String(b) Char(c) Integer(d) BooleanThis question was posed to me in a job interview.This intriguing question originated from Introduction of Console I/O Operations in division Console I/O Operations and Stream Classes of C#

Answer»

The CORRECT option is (c) Integer

The BEST 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.

43.

Select the correct methodS provided by Console.In?(a) Read(), ReadLine()(b) ReadKey(), ReadLine()(c) Read(), ReadLine(), ReadKey()(d) ReadKey(), ReadLine()The question was asked in a job interview.This question is from Introduction of Console I/O Operations in section Console I/O Operations and Stream Classes of C#

Answer»

Right option is (C) Read(), READLINE(), ReadKey()

For explanation: The TWO METHOD Read() and ReadLine() AVAILABLE in .NET Framework 1.0 and Third method ReadKey() was added by .NET Framework 2.0.

44.

The number of input methods defined by the stream method Console.In in C#.NET is?(a) 4(b) 3(c) 2(d) 1This question was posed to me in an online quiz.Enquiry is from Introduction of Console I/O Operations in section Console I/O Operations and Stream Classes of C#

Answer»

Right ANSWER is (B) 3

For explanation: Two basic methods : read() and READLINE() and third method readkey() introduced in .NET FRAMEWORK 2.0.

45.

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 mentionedI got this question in a national level competition.My question comes from Introduction of Console I/O Operations topic in portion Console I/O Operations and Stream Classes of C#

Answer»

Correct option is (c) Console.In

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.

46.

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 mentionedThis question was posed to me in unit test.My question is taken from Introduction of Console I/O Operations in division Console I/O Operations and Stream Classes of C#

Answer» CORRECT answer is (B) Console.Out

The BEST I can explain: The standard output STREAM Console.Out SENDS output to the screen by default.
47.

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.ConsoleThis question was addressed to me by my school teacher while I was bunking the class.The doubt is from Introduction of Console I/O Operations topic in portion Console I/O Operations and Stream Classes of C#

Answer»

The correct option is (d) System.Console

To explain I would say: 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.

48.

Attributes could be applied to ___________(a) Method(b) Class(c) Assembly(d) All of the mentionedI had been asked this question in an online interview.The query is from Attributes in portion Console I/O Operations and Stream Classes of C#

Answer» RIGHT CHOICE is (d) All of the mentioned

The BEST EXPLANATION: NONE.
49.

Which of the following is the correct statement about inspecting an attribute in C#.NET?(a) An attribute can be inspected at link time(b) An attribute can be inspected at design time(c) An attribute can be inspected at run time(d) None of the mentionedI have been asked this question in semester exam.This intriguing question comes from Attributes topic in chapter Console I/O Operations and Stream Classes of C#

Answer»

Right choice is (a) An ATTRIBUTE can be inspected at LINK time

Easiest EXPLANATION - NONE.

50.

Select the correct statement about Attributes used in C#.NET?(a) The CLR can change the behaviour of the code depending on attributes applied to it(b) If a bugFixAttribute is to receive three parameters, then the BugFixAttribute class should implement a zero argument constructor(c) To create a custom attribute we need to create a custom attribute structure and derive it from System.Attribute(d) None of the mentionedThe question was posed to me in an internship interview.I would like to ask this question from Attributes in chapter Console I/O Operations and Stream Classes of C#

Answer» CORRECT answer is (a) The CLR can change the BEHAVIOUR of the CODE depending on attributes applied to it

Easy explanation - NONE.