Hacker News new | ask | show | jobs
by briHass 1185 days ago
One of my favorite things about .NET now being open source (along with the frameworks like ASP.NET) is that I can easily 'peek under the hood' for various functions that I use for edge cases/details. For example, with int.TryParse(myString, out int i), what happens if myString is NULL? The docs for most of the core .NET libraries are pretty good, but nothing beats quickly parsing through the actual code. This is especially true for various constructs in ASP.NET, where the documentation frequently lags behind newer versions, and by nature, can't capture all of the possible options.

Digging deep into the core libs also makes you a better programmer by renforcing idiomatic patterns and exposing you to new techniques. Just the other day I dug into how ArgumentNullException.ThrowIfNull works, and discovered the newish (C# 10) attribute [CallerArgumentExpression("argument")] which gives you a string with the expression used to pass that parameter (i.e. in most cases, just the original variable name.) This has now entered my mental toolbox for stuff like validation code. The docs for this are actually quite good (https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...), but one has to know it's there. Often, reading other code is the best way to discover new features/techniques, and what better code to read than core .NET itself.