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?
- It indicates the stream's ability to perform seek operations. (correct)
- It checks if the stream can be closed.
- It determines if the stream can be written to.
- It verifies if the stream is currently opened.
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?
- StreamReader stream = new StreamReader(string filename);
- public StreamReader stream = new StreamReader(filename);
- StreamReader stream = new StreamReader(string filepath);
- StreamReader stream = new StreamReader(fileName); (correct)
What is the effect of the Flush() method in stream handling?
What is the effect of the Flush() method in stream handling?
- It prevents any further writing to the stream.
- It writes all data from the buffer to the file and releases file handle.
- It clears the stream and releases all resources.
- It pushes any buffered data to the stream and clears all buffers. (correct)
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?
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);?
Which of the following accurately describes the Global Assembly Cache (GAC)?
Which of the following accurately describes the Global Assembly Cache (GAC)?
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?
Which code snippet correctly creates a FileStream object?
Which code snippet correctly creates a FileStream object?
Flashcards
FileStream
FileStream
A .NET class used to create a byte-oriented stream linked to a file.
CanSeek
CanSeek
Attribute that determines if a stream responds to position requests.
OpenCreate
OpenCreate
FileMode that will create a new file if one doesn't exist.
StreamReader
StreamReader
Signup and view all the flashcards
Peek()
Peek()
Signup and view all the flashcards
Streams
Streams
Signup and view all the flashcards
CanRead
CanRead
Signup and view all the flashcards
Global Assembly Cache (GAC)
Global Assembly Cache (GAC)
Signup and view all the flashcards
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.