by Jonathan Bright | Nov 16, 2026 | Tutorials
Turn a line such as sell 12.5 kg wool @ 4.20 into a trade without scattering string splits through your game loop. This console trading post extracts named fields, converts the numbers, then checks the purse and inventory before changing either balance. The complete...
by Jonathan Bright | Nov 16, 2026 | Tutorials
A file-name text box needs a clear contract before it needs a regular expression. This tutorial builds SanitizeFileName(string): replace each character returned by Path.GetInvalidFileNameChars() with an underscore, and return an underscore for empty input. The method...
by Jonathan Bright | Nov 16, 2026 | Tutorials
A receipt test can pass on your laptop and fail on another machine because the formatter silently reads the current culture. Make that dependency visible: accept an IFormatProvider, pass it to the formatting operation, and choose the provider at the call site. This...
by Jonathan Bright | Nov 16, 2026 | Tutorials
For random draws inside a parallel loop, use Random.Shared when you want a convenient shared generator. An ordinary new Random() instance needs synchronization if multiple threads access it. A loop that happens to finish without suspicious values does not establish...
by Jonathan Bright | Nov 16, 2026 | Tutorials
A shuffle can pass once and fail the next time if its test leaves the random input uncontrolled. Give the shuffling method a Random parameter so the caller chooses the generator. Then create two fresh generators with the same seed and compare their complete deck...