C# Questions & Answers – Introduction of Stream Classes

This section of our 1000+ C# MCQs focuses 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
View Answer

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

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

Answer: c
Explanation: void close() closes the stream.
advertisement
advertisement

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

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

Answer: c
Explanation: The method used to write the contents of the stream to the physical device.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

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

Answer: b
Explanation: 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
View Answer

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

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

Answer: d
Explanation: 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
View Answer

Answer: c
Explanation:

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

Answer: b
Explanation: None.

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.