All rules
CA1514Maintainability Enabled by default: As suggestion

Avoid redundant length argument

Avoid redundant length argument

Microsoft docs

Description

An explicitly calculated length argument can be error-prone and is unnecessary when you're slicing to the end of a string or buffer.

Code that omits the length argument is more readable and maintainable.

Cause

A redundant length argument is passed to System.String.Substring, System.Span1.Slice, System.ReadOnlySpan1.Slice, or System.Memory`1.Slice when slicing to the end of a string or buffer.

How to fix violations

Remove the length argument.

Example

string message = "Hello World!";
string world = message.Substring(6, message.Length - 6); // "World!"

string message = "Hello World!";
string world = message.Substring(6); // "World!"

When to suppress

It's safe to suppress a violation of this rule if you're not concerned about the maintainability of your code.

Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0