Enumerating through .Net enums
So, I was working on something that required a loop through enumerated types (in this case, go through the different repayment methods of a mortgage calculator)
public enum RepaymentMethod
{
RepaymentOnly ,
InterestOnly,
MixOfBoth,
}
To loop through this, use Enum.GetValues() to grab an array of the enumerations, and walk through it like this:
Array repaymentMethods = Enum.GetValues(typeof(RepaymentMethod));
foreach (RepaymentMethod method in repaymentMethods)
{
calculator.RepaymentMethod = method;
calculator.doStuff();
Assert.AreEqual(0, calculator.MonthlyPayments);
}