C# Questions & Answers ? Character Stream
Posted by Superadmin on August 24 2022 10:02:23

C# Questions & Answers – Character Stream

 

 

 

 

This section of our 1000+ C# MCQs focuses on character streams of C# Programming Language.

 

 

 

1. 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 mentioned

Answer: a
Explanation: StreamWriter is derived from TextWriter. To create a character-based output stream, wrap a Stream object (such as a FileStream) inside a StreamWriter.

 

 

 

2. 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 mentioned

Answer: a
Explanation: 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.

 

 

 

 

3. Which among the following classes are used to perform the character based file operations?
a) StreamReader
b) InputReaderWriter
c) OutputStream
d) All of the mentioned

Answer: a
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.
 

4. Which of these is a method used to clear all the data present in output buffers?
a) clear()
b) flush()
c) fflush()
d) close()

Answer: b
Explanation: None.

 

 

 

5. 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 mentioned

Answer: c
Explanation: Attempts to read the count characters into buffer starting at buffer[index], returning the number of characters successfully read.
 

 

 

6. 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 mentioned

Answer: b
Explanation: Attempts to read the count characters into buffer starting at buffer[count], returning the number of characters successfully read.

 

 

 

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

Answer: a
Explanation: Obtains the next character from the input stream, but does not remove that character. Returns –1 if no character is available.

 

 

 

 

8. Which of the following is used to perform all input & output operations in C#?
a) streams
b) Variables
c) classes
d) Methods

Answer: a
Explanation: Streams are used for input and output operations in any programming language.

 

 

 

9. Which of the following is a type of stream in C#?
a) Integer stream
b) Character stream
c) Float stream
d) Long stream

Answer: b
Explanation: Two types of streams – Byte stream and character stream are defined in C#.

 

 

 

 

10. In the given constructor declaration for character based file operation what does ‘path’ and ‘bool specifies?

 StreamWriter(string path, bool append)

a) the name of the file to open
b) specifies the full path of file
c) if append is true, the file is appended to the end of the existing file
d) all of the mentioned

Answer: d
Explanation: StreamWriter(string path, bool append). Here, path specifies the name of the file to be opened, which can include a full path specifier. In the second form, if append is true, then the output is appended to the end of an existing file. Otherwise, output overwrites the specified file.