Event Driven Programming - Prefinals
8 Questions
2 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</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.</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.</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);</p> Signup and view all the answers

    Which code snippet correctly creates a FileStream object?

    <p>FileStream stream = new FileStream(string fileName, FileMode fileMode);</p> 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 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

    Untitled Quiz
    37 questions

    Untitled Quiz

    WellReceivedSquirrel7948 avatar
    WellReceivedSquirrel7948
    Untitled Quiz
    19 questions

    Untitled Quiz

    TalentedFantasy1640 avatar
    TalentedFantasy1640
    Untitled Quiz
    18 questions

    Untitled Quiz

    RighteousIguana avatar
    RighteousIguana
    Untitled Quiz
    50 questions

    Untitled Quiz

    JoyousSulfur avatar
    JoyousSulfur
    Use Quizgecko on...
    Browser
    Browser