So I was introduced to the idea of a “guard clause” in methods when I started my latest job. The idea is to make sure that all the passed in parameters of a method are, for example, not null. If they are, just throw an exception. This is what I have been doing: if(someField == [...]
Archive | Utilities
RSS feed for this section
Random String of Specified Length with Enumerable
using System; using System.Collections.Generic; using System.Linq; using System.Text; public static String RandomString(Int32 length) { Random randomGenerator; String returnValue; randomGenerator = new Random(); returnValue = new string(Enumerable.Range(0, length).Select(i => (char)(‘A’ + randomGenerator.Next(0, 25))).ToArray()); return returnValue; } What this does: Enumerable.Range basically says, “Give me a collection of numbers from the first parameter to the second”, or [...]