Chapter 8 – Working with Common .NET Types Flashcards

1
Q

What is the maximum number of characters that can be stored in a string variable?

A

The maximum size of a string variable is 2 GB or about 1 billion characters, because
each char uses 2 bytes due to the internal use of Unicode (UTF-16) encoding for characters
in a string.

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

When and why should you use a SecureString type?

A

The string type leaves text data in the memory for too long and it’s too visible. The
SecureString type encrypts its text and ensures that the memory is released immediately.
For example, in WPF, the PasswordBox control stores its password as a SecureString variable,
and when starting a new process, the Password parameter must be a SecureString variable.

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

When is it appropriate to use a StringBuilder class?

A

When concatenating more than about three string variables, you will use less memory
and get improved performance using StringBuilder than using the string.Concat method
or the + operator.

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

When should you use a LinkedList<T> class?</T>

A

Each item in a linked list has a reference to its previous and next siblings as well as
the list itself. A linked list should be used when items need to be inserted and removed from
positions in the list without moving the items in memory.

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

When should you use a SortedDictionary<T> class rather than a SortedList<T> class?</T></T>

A

The SortedList<T> class uses less memory than SortedDictionary<T>;
SortedDictionary<T> has faster insertion and removal operations for unsorted data. If the list
is populated all at once from sorted data, SortedList<T> is faster than SortedDictionary<T>.</T></T></T></T></T>

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

In a regular expression, what does $ mean?

A

In a regular expression, $ represents the end of the input.

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

In a regular expression, how can you represent digits?

A

In a regular expression, you can represent digit characters using \d or [0-9].

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

Why should you not use the official standard for email addresses to create a regular expression
to validate a user’s email address?

A

The effort is not worth the pain for you or your users. Validating an email address
using the official specification doesn’t check whether that address exists or whether the person
entering the address is its owner.

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

What characters are output when the following code runs?

string city = “Aberdeen”;
ReadOnlySpan<char> citySpan = city.AsSpan()[^5..^0];
WriteLine(citySpan.ToString());</char>

A

rdeen. ^5.. means the range is 5 characters long. ..^0 means the range ends zero
characters in from the right end.

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

What characters are output when the following code runs?

string city = “Aberdeen”;
ReadOnlySpan<char> citySpan = city.AsSpan()[^5..^0];
WriteLine(citySpan.ToString());</char>

A

rdeen. ^5.. means the range is 5 characters long. ..^0 means the range ends zero
characters in from the right end.

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

What characters are output when the following code runs?
string city = “Aberdeen”;
ReadOnlySpan<char> citySpan = city.AsSpan()[^5..^0];
WriteLine(citySpan.ToString());</char>

A

rdeen. ^5.. means the range is 5 characters long. ..^0 means the range ends zero
characters in from the right end.

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

How could you check that a web service is available before calling it?

A

Use the Ping class to call the web service and check the Status of the reply.

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