CA1023: Indexers should not be multidimensional
Visual Studio 2010
TypeName | IndexersShouldNotBeMultidimensional |
CheckId | CA1023 |
Category | Microsoft.Design |
Breaking Change | Breaking |
The following example shows a type, DayOfWeek03, with a multi-dimensional indexer that violates the rule. The indexer can be seen as a type of conversion and therefore is more appropriately exposed as a method. The type is redesigned in RedesignedDayOfWeek03 to satisfy the rule.
using System; namespace DesignLibrary { public class DayOfWeek03 { string[,] dayOfWeek = {{"Wed", "Thu", "..."}, {"Sat", "Sun", "..."}}; // ... public string this[int month, int day] { get { return dayOfWeek[month - 1, day - 1]; } } } public class RedesignedDayOfWeek03 { string[] dayOfWeek = {"Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Mon"}; int[] daysInPreviousMonth = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30}; public string GetDayOfWeek(int month, int day) { return dayOfWeek[(daysInPreviousMonth[month - 1] + day) % 7]; } } }