Download presentation
Presentation is loading. Please wait.
Published byFelix Maxwell Modified over 8 years ago
1
CSCI 3328 Object Oriented Programming in C# Chapter 11: Files and Streams -- Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539 xiang.lian@utrgv.edu
2
Objectives In this chapter, you will do some exercises about: –Windows GUI –Classes File and Directory –LINQ queries to search through directories –sequential-access file processing –Classes FileStream, StreamReader, StreamWriter, FileStream, and BinaryFormatter 2
3
Multiple Choices The smallest data item a computer can process is called a ________. –A. database B. byte C. file D. bit A group of related records is stored in a ____. –A. file B. field C. bit D. byte Data maintained in a file is called _____. –A. persistent data B. bits C. secondary data D. databases Methods from the ____ class can be used to write data to a file. –A. StreamReader B. WriteFile C. StreamWriter D. None of the above Namespace ____ provides the classes and methods you need to perform file processing. –A. System.IO B. System.Files C. System.Stream D. System.Windows.Forms A(n) ____ allows the user to select a file to open. –A. CreateFileDialog B. OpenFileDialog C. MessageBox D. SaveFileDialog 3
4
Multiple Choices (cont'd) StreamReader method _____ reads a line from a file. –A. ReadLine B. Read C. ReadAll D. ReadToNewline A _____contains information that is read in the order it was written. –A. sequential-access file B. StreamWriter C. StreamReader D. None of the above Methods from class _____ can be used to read data from a file. –A. StreamWriter B. FileReader C. StreamReader D. None of the above Ultimately, all data items processed by a computer are reduced to combinations of _________. –A. 0-9 B. 'a'-'z' C. 'A'-'Z' D. 0's and 1's Method Serialize of class BinaryFormatter takes a(n) _______ and a(n) __________ as arguments. –A. object and Stream B. Stream and object C. File and object D. object and File 4
5
True / False Statement Creating instances of classes File and Directory is impossible. Typically, a sequential file stores records in order by the record-key fields. Class StreamReader inherits from class Stream. Any class can be serialized to a file. Classes StreamReader and StreamWriter are used with sequential-access files. The class BinaryFormatter is under the namespace System.Runtime.Serialization.Formatters.Binary. 5
6
True / False Statement (cont'd) The ListBox control allows only a single selection (like a RadioButton). Controls such as form, GroupBox, Panel, and TabControl are all containers. All mouse events use the same event arguments class. A ComboBox control typically has a drop-down list. Deleting a parent node in a TreeView control deletes its child nodes. 6
7
Writing the C# Code A student record has information such as student ID, last name, first name, birth year, and so on. –Declare a class for a student record –Write a method to write records into a file, using StreamWriter –Write a method to read records from a file into a record array, using StreamReader –Use an LINQ query to find those students with the birth year > 1981, and write them into another file using BinaryFormatter 7
8
8
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.