C# Month, Day ArraysThis C# example program uses arrays of strings containing month and day names.
Month, day arrays.
Date names can be stored in an array. The .NET Framework can programmatically return month and day strings. But it is more efficient to store them in string literals and then simply load the correct strings from the metadata.String ArrayString Literal
In this program the days of the week are numbered zero through six and the months are numbered one through twelve. To accommodate these indexes, we set up two static arrays with the appropriate string literals stored in them.Static Array
Then: When we want to load the correct date string, we can pass an integer and the helper methods will return the value.
Info: This class will enable you to make specific changes to the representations of the date strings. This results in more flexibility.
C# program that stores months and days
static void Main()
// Test the DateArrays class.
static class DateArrays
static string _months =
static string _days =
/// Get month (1 = January)
public static string GetMonth(int number)
/// Get day (0 = Sunday)
public static string GetDay(int number)
Once initialized, this class will not require any allocations during runtime. The string literals are actually stored in the metadata on the disk and will always be in memory. The operating system does not need to be queried.
Note: The main drawback to this class is that it cannot be changed based on the user's locale.
However: For some applications, such as those with standard requirements, this limitation is desirable.
In this example class, we stored string literals corresponding to the DateTime integers. This achieves a startup time improvement and memory reduction. It requires no operating system queries.DateTime
© 2007-2019 Sam Allen. Every person is special and unique. Send bug reports to firstname.lastname@example.org.