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
View Answer

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
View Answer

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
View Answer

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

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

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
View Answer

Answer: c
Explanation: Attempts to read the count characters into buffer starting at buffer[index], returning the number of characters successfully read.
Note: Join free Sanfoundry classes at Telegram or Youtube

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
View Answer

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
View Answer

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

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

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
View Answer

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

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
View Answer

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.

Sanfoundry Global Education & Learning Series – C# Programming Language.

To practice all areas of C# language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.