Skip to content

Files

Latest commit

 

History

History
27 lines (17 loc) · 657 Bytes

File metadata and controls

27 lines (17 loc) · 657 Bytes

Pattern: Redundant length argument

Issue: -

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.

Example of incorrect code:

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

Example of correct code:

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

Further Reading