250+ TOP MCQs on Introduction of Stream Classes and Answers

C# MCQs on introduction of stream classes in C# Programming Language.

1. Select the namespace on which the stream classes are defined?
a) System.IO
b) System.Input
c) System.Output
d) All of the mentioned

Answer: a
Clarification: 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;

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

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

3. Choose the stream class method which is used to close the connection?
a) close()
b) static close()
c) void close()
d) none of the mentioned

Answer: c
Clarification: void close() closes the stream.

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

Answer: a
Clarification: Writes a single byte to an output stream.

5. Select the method which writes the contents of the stream to the physical device.
a) fflush()
b) void fflush()
c) void Flush()
d) flush()

Answer: c
Clarification: The method used to write the contents of the stream to the physical device.

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

Answer: b
Clarification: Writes a subrange of count bytes from the array buffer, beginning at buffer[offset], returning the number of bytes written.

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

Answer: b
Clarification: Returns an integer representation of the next available byte of input. Returns –1 when the end of the file is encountered.

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

Answer: d
Clarification: None.

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

Answer: c
Clarification:

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.

10. Which among the following attempts to read up to count bytes into buffer starting at buffer[offset], returning the number of bytes successfully read?
a) int ReadByte()
b) int Read(byte[] buffer, int offset, int count)
c) Void WriteByte(byte value)
d) None of the mentioned

Answer: b
Clarification: None.

Leave a Reply

Your email address will not be published. Required fields are marked *