Event Driven Programming - Prefinals
8 Questions
9 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

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?

  • 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?

  • 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?

<p>OpenOrCreate (C)</p> 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);?

<p>It returns the next character or -1 if no more characters are available. (A)</p> Signup and view all the answers

Which of the following accurately describes the Global Assembly Cache (GAC)?

<p>It allows multiple applications to share assemblies. (B)</p> Signup and view all the answers

What method is used to read a block of bytes from a stream?

<p>public override int Read(byte[] arr, int offset, int count); (C)</p> Signup and view all the answers

Which code snippet correctly creates a FileStream object?

<p>FileStream stream = new FileStream(string fileName, FileMode fileMode); (C)</p> Signup and view all the answers

Flashcards

FileStream

A .NET class used to create a byte-oriented stream linked to a file.

CanSeek

Attribute that determines if a stream responds to position requests.

OpenCreate

FileMode that will create a new file if one doesn't exist.

StreamReader

A .NET class used to read from a text file.

Signup and view all the flashcards

Peek()

Retrieves the next character without advancing the file pointer.

Signup and view all the flashcards

Streams

Sources that send a series of bytes, like I/O devices.

Signup and view all the flashcards

CanRead

Stream property that indicates if a stream can be read.

Signup and view all the flashcards

Global Assembly Cache (GAC)

Location for shared assemblies, allowing multiple apps to use the same code.

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 returns true 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 a StreamReader for a specified file.

FileStream and StreamWriter

  • Question 10: FileStream(string fileName, FileMode fileMode) creates a FileStream 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 create StreamWriter. Then Flush() the StreamWriter.
  • 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.

Quiz Team

Related Documents

More Like This

Event-driven Programming Quiz
3 questions
Understanding Event-Driven Programming
10 questions
CS341 Week 02: Event-Driven Programming
48 questions

CS341 Week 02: Event-Driven Programming

ComplementaryPreRaphaelites212 avatar
ComplementaryPreRaphaelites212
Use Quizgecko on...
Browser
Browser