Custom default values for not existing dictionary items (and a lesson learned)

When dealing with dictionaries, a typical problem is when an operation attempts to retrieve an element using a key that does not exist in the dictionary. In .NET, a KeyNotFoundException is raised, and that’s the desired behaviour in most circumstances. Sometimes, however, you know that your program will frequently try to retrieve keys that do not exist. In such cases, it is more efficient to use the TryGetValue method: This method returns the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter is returned (source) »

dotnet SmtpClient should not be used

I am very late to the party, but today I learned that the good old dotnet SmptClient is considered obsolete and should not be used. Quoting the documentation: We don’t recommend using the SmtpClient class for new development because SmtpClient doesn’t support many modern protocols. Use MailKit or other libraries instead. (source) Interestingly, Microsoft is recommending a third-party open-source library as an alternative. I hope we’ll see more of that in the future. »