Podcast
Questions and Answers
What is the purpose of the CanSeek attribute in a stream?
What is the purpose of the CanSeek attribute in a stream?
Which code correctly initializes a new instance of the StreamReader class for a specified file name?
Which code correctly initializes a new instance of the StreamReader class for a specified file name?
What is the effect of the Flush() method in stream handling?
What is the effect of the Flush() method in stream handling?
Which FileMode option is used to open an existing file and create a new one if it doesn’t exist?
Which FileMode option is used to open an existing file and create a new one if it doesn’t exist?
Signup and view all the answers
In the context of streams, what is the result of reading from an input stream with the following syntax: int val = streamReader.Read(); Console.WriteLine(val);?
In the context of streams, what is the result of reading from an input stream with the following syntax: int val = streamReader.Read(); Console.WriteLine(val);?
Signup and view all the answers
Which of the following accurately describes the Global Assembly Cache (GAC)?
Which of the following accurately describes the Global Assembly Cache (GAC)?
Signup and view all the answers
What method is used to read a block of bytes from a stream?
What method is used to read a block of bytes from a stream?
Signup and view all the answers
Which code snippet correctly creates a FileStream object?
Which code snippet correctly creates a FileStream object?
Signup and view all the answers
Study Notes
Event-Driven Programming
-
Question 1:
Peek()
retrieves a value from a stream without changing the file pointer. - Question 2: Streams are sources like I/O devices that transmit byte sequences.
-
Question 3: The
CanSeek
attribute determines if a stream supports position requests. -
Question 4:
.dll
files are reusable components. -
Question 5:
CanRead
returnstrue
if a stream can be read. -
Question 6: To create a byte-oriented stream associated with a file, use the
FileStream
class. -
Question 7: An assembly's
Manifest
includes name, version, and mapping information. -
Question 8:
OpenCreate
opens a file, creating it if it doesn't exist. -
Question 9:
public StreamReader(string filename)
initializes aStreamReader
for a specified file.
FileStream and StreamWriter
-
Question 10:
FileStream(string fileName, FileMode fileMode)
creates aFileStream
object. -
Question 11:
StreamReader(string fileName)
sets the file name. -
Question 12:
Flush()
empties the current stream's buffer contents. -
Question 13:
int val = streamReader.Read(); Console.WriteLine(val)
reads and displays stream content.
Global Assembly Cache (GAC)
- Question 14: The GAC lets multiple apps share assemblies.
Stream Operations
-
Question 15:
public override int Read(byte[] arr, int offset, int count)
reads bytes from a stream. -
Question 16:
long Seek(long varNum, SeekOrigin position)
adjusts the file pointer's position.
Private vs. Shared Assemblies
- Private assemblies are used by a single application, offering isolation and easy deployment.
- Shared assemblies are stored in the Global Assembly Cache (GAC) and allow multiple applications to reuse the same code, promoting consistency and centralized management.
- The choice depends on prioritizing code reuse against isolation within a project.
StreamWriter Creation and Check
-
New StreamWriter: use
FileStream
as a parameter to createStreamWriter
. ThenFlush()
theStreamWriter
. -
File Writability: Use
myStream.CanWrite
to check if a FileStream is writable, displaying appropriate messages based on the result.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.