Skip to main content

SingleElementConcat

Diagnostic Rule Overview

FieldValue
IDSHIMMER1101
Analyzer titleSimplify .Concat()
Analyzer messageReplace .Concat([e]) with .Append(e)
Code fix titleReplace .Concat([e]) with .Append(e)
Default severityInfo
Minimum framework/language versionN/A
CategoryShimmeringUsage
Link to codeSingleElementConcatAnalyzer.cs
Code fix exists?Yes

Detailed Explanation

Using Enumerable.Concat() to add a single element is semantically imprecise and may mislead readers about the intent of the code. The analyzer flags these instances because .Concat() is designed for merging two enumerables, while .Append() more clearly indicates the addition of one element to an existing enumerable.

Examples

Flagged code:

var result = new[] { 1, 2 }.Concat(new[] { 3 });

Fixed code:

var result = new[] { 1, 2 }.Append(3);

Another scenario involving a cast:

Flagged code:

this._field = new[] { 1, 2 }.Concat((int[])[3]);

Fixed code:

this._field = new[] { 1, 2 }.Append(3);

Justification of the Severity

While the fixed code is more concise and clear, this has negligible impact on performance and does not cause any bugs.

When to Suppress

Suppress this diagnostic when you want to use .Concat() consistently.