All rules
IDE0056Language rules (expression-level preferences)

Use index operator

Use index operator

Microsoft docs

Description

This style rule concerns the use of the index-from-end operator (^), which is available in C# 8.0 and later.

Example

// csharp_style_prefer_index_operator = true
string[] names = { "Archimedes", "Pythagoras", "Euclid" };
var index = names[^1];

// csharp_style_prefer_index_operator = false
string[] names = { "Archimedes", "Pythagoras", "Euclid" };
var index = names[names.Length - 1];

Configurable options

Vote for the value each option should take in the generated .editorconfig.

csharp_style_prefer_index_operator
default: true
Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0