CodeRush Classic shows the Indexer cannot be static code issue if an indexer is marked static.
Fix
Remove the static modifier from the indexer declaration.
Purpose
Highlights the declaration statements, which would cause the The modifier 'static' is not valid for this item compilation error.
Example
public class MyClass
{
public static string │this[int i]
{
get
{
return _Strings[i];
}
set
{
_Strings[i] = value;
}
}
private static List<string> _Strings;
public static void AddString(string value)
{
if (_Strings == null)
_Strings = new List<string>();
_Strings.Add(value);
}
}
Fix:
public class MyClass
{
public string this[int i]
{
get
{
return _Strings[i];
}
set
{
_Strings[i] = value;
}
}
private static List<string> _Strings;
public static void AddString(string value)
{
if (_Strings == null)
_Strings = new List<string>();
_Strings.Add(value);
}
}
We are updating the DevExpress product documentation website and this page is part of our new experience. During this transition period, product documentation remains available in our previous format at documentation.devexpress.com. Learn More...