C#

C#

Made by DeepSource

Avoid chaining of index lookup and .Substring method CS-P1007

Performance
Major

Index lookup methods such as IndexOf, LastIndexOf, IndexOfAny, and LastIndexOfAny return the index of the char depending on the arguments supplied. Chaining such calls to .Substring requires that a part of the string be selected and then the char be looked up. Instead, consider calling the index lookup methods directly and then subtracting the begin offset.

Example

Bad practice

var c = 'C';
var pos = str.Substring(beg).IndexOf(c);

Reference