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
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
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
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()
View Answer
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
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
View Answer
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
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
View Answer
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
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
View Answer
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.
- Apply for Computer Science Internship
- Check C# Books
- Apply for C# Internship
- Check MCA Books
- Practice Computer Science MCQs