Chapter 9 – Working with Files, Streams, and Serialization Flashcards

1
Q

What is the difference between using the File class and the FileInfo class?

A

The File class has static methods and it cannot be instantiated. It is best used for oneoff tasks such as copying a file. The FileInfo class requires the instantiation of an object that
represents a file. It is best used when you need to perform multiple operations on the same file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the difference between the ReadByte method and the Read method of a stream?

A

The ReadByte method returns a single byte each time it is called and the Read method fills a temporary array with bytes up to a specified length. It is generally best to use Read to process multiple bytes at once.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When would you use the StringReader, TextReader, and StreamReader classes?

A
  • StringReader is used for efficiently reading from a string stored in memory.
  • TextReader is an abstract class that StringReader and StreamReader both inherit from
    for their shared functionality.
  • StreamReader is used for reading strings from a stream that can be any type of text
    file, including XML and JSON.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the DeflateStream type do?

A

DeflateStream implements the same compression algorithm as GZIP, but without a
cyclical redundancy check; so, although it produces smaller compressed files, it cannot perform integrity checks when decompressing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How many bytes per character does UTF-8 encoding use?

A

The number of bytes per character used by the UTF-8 encoding depends on the
character. Most Western alphabet characters are stored using one byte. Other characters may
need two or more bytes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is an object graph?

A

An object graph is any set of connected instances of classes that reference each other.
For example, a Customer object may have a property named Orders that references a collection
of Order instances.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the best serialization format to choose for minimizing space requirements?

A

JavaScript Object Notation (JSON) has a good balance between space requirements
and practical factors like human readability, but the protocol buffers (Protobuf) serialization
format used by the gRPC standard is best for minimizing space requirements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the best serialization format to choose for cross-platform compatibility?

A

There is still an argument for eXtensible Markup Language (XML) if you need maximum compatibility, especially with legacy systems, although JSON is better if you need to integrate with web systems, or protocol buffers for best performance and minimum bandwidth use.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why is it bad to use a string value like “\Code\Chapter01” to represent a path, and what
should you do instead?

A

It is bad to use a string value like “\Code\Chapter01” to represent a path because
it assumes that backslashes are used as a folder separator on all operating systems. Instead,
you should use the Path.Combine method and pass separate string values for each folder, or
a string array, as shown in the following code:
string path = Path.Combine(new[] { “Code”, “Chapter01” });

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Where can you find information about NuGet packages and their dependencies?

A

You can find information about NuGet packages and their dependencies at the following link: https://www.nuget.org/.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly