Use integral or string argument for indexers
Use integral or string argument for indexers
Microsoft docsDescription
Indexers, that is, indexed properties, should use integer or string types for the index. These types are typically used for indexing data structures and increase the usability of the library. Use of the System.Object type should be restricted to those cases where the specific integer or string type cannot be specified at design time. If the design requires other types for the index, reconsider whether the type represents a logical data store. If it does not represent a logical data store, use a method.
Cause
A type contains an indexer that uses an index type other than System.Int32, System.Int64, System.Object, or System.String.
By default, this rule only looks at externally visible types, but this is configurable.
How to fix violations
To fix a violation of this rule, change the index to an integer or string type or use a method instead of the indexer.
Example
string[] Month = new string[] { "Jan", "Feb", "..." };
public string this[int index]
{
get => Month[index];
}When to suppress
Suppress a warning from this rule only after carefully considering the need for the nonstandard indexer.