"When I first found this custom 'enum'," writes Garrett Hopp," I had assumed that my predecessor had re-implemented the DayOfWeek Enumeration. I suppose that wouldn't be that big of a WTF as discovering the built-in DayOfWeek
does involve using a search engine... which many developers seem to struggle with."
"But upon closer inspection, I realized it's a bit more than that, and is a really clever way to write (int) DateTime.Now.DayOfWeek
. After all, that'd just be lazy."
using System; using System.Collections; // for Hashtable namespace DayOfWeekEnum { /// <summary> /// This class contains utilities commonly used in DRX and OBL /// </summary> public class getDayOfWeekEnum { public getDayOfWeekEnum() { } public static string getDayEnum() { // HashTable for to get 0-6 from Sunday-Saturday Hashtable dayOfWeek = new Hashtable(); dayOfWeek.Add("Sunday", "0"); dayOfWeek.Add("Monday", "1"); dayOfWeek.Add("Tuesday", "2"); dayOfWeek.Add("Wednesday", "3"); dayOfWeek.Add("Thursday", "4"); dayOfWeek.Add("Friday", "5"); dayOfWeek.Add("Saturday", "6"); DateTime today = DateTime.Now; string dayOfWeekStr = String.Format("{0}", today.DayOfWeek); string dayEnum = dayOfWeek[dayOfWeekStr].ToString(); return dayEnum; } } }
[Advertisement]
BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!