Chapter 8 – Working with Common .NET Types Flashcards
What is the maximum number of characters that can be stored in a string variable?
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.
When and why should you use a SecureString type?
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.
When is it appropriate to use a StringBuilder class?
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.
When should you use a LinkedList<T> class?</T>
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.
When should you use a SortedDictionary<T> class rather than a SortedList<T> class?</T></T>
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>
In a regular expression, what does $ mean?
In a regular expression, $ represents the end of the input.
In a regular expression, how can you represent digits?
In a regular expression, you can represent digit characters using \d or [0-9].
Why should you not use the official standard for email addresses to create a regular expression
to validate a user’s email address?
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.
What characters are output when the following code runs?
string city = “Aberdeen”;
ReadOnlySpan<char> citySpan = city.AsSpan()[^5..^0];
WriteLine(citySpan.ToString());</char>
rdeen. ^5.. means the range is 5 characters long. ..^0 means the range ends zero
characters in from the right end.
What characters are output when the following code runs?
string city = “Aberdeen”;
ReadOnlySpan<char> citySpan = city.AsSpan()[^5..^0];
WriteLine(citySpan.ToString());</char>
rdeen. ^5.. means the range is 5 characters long. ..^0 means the range ends zero
characters in from the right end.
What characters are output when the following code runs?
string city = “Aberdeen”;
ReadOnlySpan<char> citySpan = city.AsSpan()[^5..^0];
WriteLine(citySpan.ToString());</char>
rdeen. ^5.. means the range is 5 characters long. ..^0 means the range ends zero
characters in from the right end.
How could you check that a web service is available before calling it?
Use the Ping class to call the web service and check the Status of the reply.