C# Questions & Answers ? Byte Stream
Posted by Superadmin on August 24 2022 09:58:47

C# Questions & Answers – Byte Stream

 

 

This section of our 1000+ C# MCQs focuses in detail on byte stream in C# Programming Language.

 

 

 

1. Which of these classes is used to read and write bytes in a file?
a) FileReader
b) FileWriter
c) FileInputStream
d) InputStreamReader

Answer: c
Explanation: None.

 

 

 

2. Which of these data types is returned by every method of OutputStream?
a) int
b) float
c) byte
d) none of the mentioned

Answer: d
Explanation: Every method of OutputStream returns void and throws an IOExeption in case of errors.

 

 

 

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

Answer: a
Explanation: InputStream & OutputStream are designed for byte stream. Reader and writer are designed for character stream.
 

 

 

4. Which among the following is used for storage of memory aspects?
a) BufferedStream
b) FileStream
c) MemoryStream
d) None of the mentioned

Answer: c
Explanation: A byte stream that uses memory for storage.

 

 

 

 

5. Which among the following is used for storage of unmanaged memory aspects?
a) BufferedStream
b) FileStream
c) MemoryStream
d) UnmanagedMemoryStream

Answer: d
Explanation: A byte stream that uses unmanaged memory for storage.
 

 

 

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

Answer: a
Explanation: This property contains the length of the stream. This property is read-only.

 

 

 

 

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

Answer: a
Explanation: Creates a new output file. The file must not already be existing.

 

 

 

 

8. 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.Truncate

Answer: b
Explanation: Creates a new output file. Any pre-existing file with the same name will be destroyed.

 

 

 

 

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

Answer: b
Explanation: None.

 

 

 

 

10. Which of these is a method used for reading bytes from the file?
a) clear()
b) ReadByte()
c) put()
d) write()

Answer: b
Explanation: FileStream defines two methods that reads bytes from a file: ReadByte() and Read().