Chapter 4 – Using Common .NET Types
Does every assembly that you create have a reference to the
mscorlib.dll
assembly?No. Although by default every assembly will have an automatic reference to the
mscorlib.dll
assembly, there is a compiler flag that can prevent this. For details, visit:https://msdn.microsoft.com/en-us/library/fa13yay7.aspx
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 eachchar
variable uses 2 bytes due to the internal use of Unicode (UTF-16) encoding for characters.When and why should you use the
SecureString
type?The
string
type leaves text data in memory for too long and it's too visible. TheSecureString
type encrypts the text and ensures that the memory is released immediately. WPF'sPasswordBox
control stores the password as aSecureString
variable, and when starting a new process, thePassword
parameter must be aSecureString
variable. For more discussion, visit:http://stackoverflow.com/questions/141203/when-would-i-need-a-securestring-in-net
When should you use a
LinkedList<T>
variable?Each item in a linked list has a reference to its previous and next siblings as well as the list itself so should be used when items need to be inserted and removed from positions in the list without actually moving the items in memory.
When should you use a
SortedDictionary
variable rather than aSortedList
variable?The
SortedList
class uses less memory thanSortedDictionary
,SortedDictionary
has faster insertion and removal operations for unsorted data. If the list is populated all at once from sorted data,SortedList
is faster thanSortedDictionary
. For more discussion, visit:http://stackoverflow.com/questions/935621/whats-the-difference-between-sortedlist-and-sorteddictionary
Why should you not use the official standard for e-mail addresses to create a regular expression to validate a user's e-mail address?
The effort is not worth the pain for you or your users. Validating an e-mail address using official specification doesn't check whether that address actually exists or whether the person entering the address is its owner. For more discussion, visit:
http://davidcel.is/posts/stop-validating-email-addresses-with-regex/
http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address