C# fourth homework

Assignment 4 20230425183015

Number of questions: 21 Full marks: 100

Answer time: 04-25 18:43 to 05-09 17:44                                               95.2 minutes

1. Multiple choice questions (21 questions in total, 100 points)

1. (Single-choice question) When using the FileStream object to open a file, the FileMode parameter can be used to control _____________.

  • A. Which operations in the file overwrite, create, open and other options
  • B. Read-only, write-only, or read/write to the file
  • C. The type of access that other FileStream objects have to the same file
  • D. Anchors for random access to files

My answer:  A: Which operations are in the options of file overwriting, creation, opening, etc.; Correct answer:  A: Which operations are in the options of file overwriting, creation, and opening;

4.7 points

2. (Single-choice question) When using the FileStream object to open a file, use the ______________ member of the FileMode enumeration type to specify the operating system to open an existing file and position the file read/write pointer at the end of the file.

  • A. Append
  • B. Create
  • C. CreateNew
  • D. Truncate

My answer:  A:Append; Correct answer:  A:Append;

4.7 points

3. (Single-choice question) Suppose you want to use C# to design a log system. It is required to check whether the system.log file exists when the program is running. If it already exists, open it directly. If it does not exist, create one. In order to achieve this, we should use FileMode's __________________ way to create a file stream.

  • A. CreateNew
  • B. Open
  • C. OpenOrCreate
  • D. Create

My answer:  C:OpenOrCreate; Correct answer:  C:OpenOrCreate;

4.7 points

4. (Single-choice question) The ______________ method should be used to read the contents of the file from the current position to the end.

  • A. StreamReader.ReadToEnd()
  • B. StreamReader.ReadLine()
  • C. StreamReader.ReadBlock()
  • D. StreamReader.WriteLine()

My answer:  A:StreamReader.ReadToEnd(); Correct answer:  A:StreamReader.ReadToEnd();

4.7 points

5. (Single-choice question) The ____________________ method of the FileStream class is used to locate the file location pointer.

  • A. Close
  • B. Seek
  • C. Lock
  • D. Flush

My answer:  B:Seek; Correct answer:  B:Seek;

4.7 points

6. (Single-choice question) The following statement defines and initializes an integer array a:
int[ ] a=new int[400];
for(int i=0; i<400: i++) a[i]=i;
for Write all element values ​​of the array a into the FileStream stream, and create an instance of the _______________ class to write to the stream.

  • A. BinaryWriter
  • B. StreamWriter
  • C. TextWriter
  • D. StringWriter

My answer:  A:BinaryWriter; Correct answer:  A:BinaryWriter;

4.7 points

7. (Single-choice question) The correct statement about the following C# code is __________________.
FileStream fs=new FileStream("d:\\music.txt",FileMode.OpenOrCreate);

  • A. If there is no file music.txt in the root directory of disk D, an exception will occur when the code is running
  • B. If the file music.txt exists in the root directory of drive D, an exception will occur when the code is running
  • C. There is a syntax error in the statement
  • D. After the code is executed, the file music.txt must exist in the root directory of disk D

My answer:  D: After the code is executed, the file music.txt must exist in the root directory of drive D; Correct answer:  D: After the code is executed, the file music.txt must exist in the root directory of drive D;

4.7 points

8. (Single-choice question) The Directory class and DirectoryInfo class provide methods for basic directory operations. The following _______________ are not valid directory path parameters.

  • A. c:\Mydir
  • B. c:\\MyDir
  • C. \\\\MyServer\\MyShare
  • D. @“c:\MyDir”

My answer:  A:c:\Mydir; Correct answer:  A:c:\Mydir;

4.7 points

9. (Single-choice question) To determine information such as drive capacity and available free space, you can use the _________________ class in the .NET Framework class library.

  • A. Directory
  • B. DriveInfo
  • C. File
  • D. FileStream

My answer:  B:DriveInfo; Correct answer:  B:DriveInfo;

4.8 points

10. (Single-choice question) To delete a directory, you can use the _____________ class in the .NET Framework class library.

  • A. DriveInfo
  • B. Directory
  • C. File
  • D. FileStream

My answer:  B:Directory; Correct answer:  B:Directory;

4.8 points

11. (Single-choice question) To rename a file, you can use the _____________ class in the .NET Framework class library.

  • A. DriveInfo
  • B. Directory
  • C. File
  • D. FileStream

My answer:  C:File; Correct answer:  C:File;

4.8 points

12. (Single-choice question) To write a string to a file, you can use the _________________ class in the .NET Framework class library.

  • A. File
  • B. FileInfo
  • C. StringWriter
  • D. FileStream

My answer:  C:StringWriter; Correct answer:  C:StringWriter;

4.8 points

13. (Single choice) To randomly access binary files, you can use the ________________ class in the .NET Framework class library.

  • A. File
  • B. FileInfo
  • C. StringWriter
  • D. FileStream

My answer:  D:FileStream; Correct answer:  D:FileStream;

4.8 points

14. (Single-choice question) Which of the following is not a file access method is _______________.

  • A. read-only
  • B. write only
  • C. read/write
  • D. neither read nor write

My answer:  D: neither read nor write; correct answer:  D: neither read nor write;

4.8 points

15. (Single-choice question) The following ________________ class provides folder operation functions.

  • A. File
  • B. Directory
  • C. FileStream
  • D. BinaryWriter

My answer:  D:BinaryWriter; Correct answer:  B:Directory;

0 points

16. (Single-choice question) Which of the following declarations for enumerated types is ______________.

  • A. enum a={one,two,three};
  • B. enum b {a1,a2,a3};
  • C. whether c={'1','2','3'};
  • D. enum d {"one","two","three"};

My answer:  B:enum b {a1,a2,a3};; Correct answer:  B:enum b {a1,a2,a3};;

4.8 points

17. (Single-choice question) The declaration statement about enumeration: "enum Colors {Red, green, blue, yellow};", the following statement is correct _________________.

  • A. Colors is a field in a class
  • B. Colors is a class, but does not have any constructor
  • C. Colors is an object, { } are the 4 fields of the object
  • D. Colors is a type, and an object can be created with Colors

My answer:  D: Colors is a type, and an object can be created with Colors; Correct answer:  D: Colors is a type, and an object can be created with Colors;

4.8 points

18. (Single-choice question) Among the following modifiers, structure members can use _____________.

  • A. protected
  • B. abstract
  • C. virtual
  • D. internal

My answer:  D:internal; Correct answer:  D:internal;

4.8 points

19. (Single-choice question) Which of the following statements about structure is correct ___________.

  • A. Function members in structures cannot be abstract or virtual
  • B. A structure cannot declare a default constructor (a constructor without parameters), but can declare a destructor
  • C. The structure has only data members and no methods
  • D. A structure cannot be used as the base class of a class, but it can be derived from another class

My answer:  A: The function members in the structure cannot be abstract or virtual; the correct answer:  A: The function members in the structure cannot be abstract or virtual;

4.8 points

20. (Single-choice question) Which of the following statements about structure is correct ________________.

  • A. Every structure implicitly has a parameterless instance constructor
  • B. Allow declaring destructors in structs
  • C. The instantiation of the structure must use the new operator
  • D. The accessibility of structure members can be protected or protected internal

My answer:  A: Every structure implicitly has a parameterless instance constructor; Correct answer:  A: Every structure implicitly has a parameterless instance constructor;

4.8 points

21. (Single-choice question) Which of the following statements about structure is correct ______________.

  • A. Structures cannot be passed to function members by reference through ref or out parameters
  • B. Structs are value types while classes are reference types
  • C. Structures, like classes, support inheritance
  • D. Structs allow the declaration of instance constructors with no parameters

My answer:  B: The structure is a value type, while the class is a reference type; the correct answer:  B: The structure is a value type, and the class is a reference type;

Guess you like

Origin blog.csdn.net/qq_46476515/article/details/130396330
Recommended