When the call to a function doesn’t have any side effects, what is the point of making the call if the results are ignored? In such case, either the function call is useless and should be dropped or the source code doesn’t behave as expected.
This rule raises an issue when the results of the following methods are ignored:
[Pure] method, string, int, …, System.Collections.Immutable.ImmutableArray<T>,
ImmutableHashSet<T>, … Notes:
string.Intern has a side effect, ignoring its return value is still suspicious as it is the only reference ensured to
point to the intern pool.
tests.All(c => { c.myfield = "foo"; return true; });
Such code should be rewritten as a normal loop.
coll.Where(i => i > 5).Select(i => i*i); // Noncompliant
"this string".Equals("other string"); // Noncompliant
var res = coll.Where(i => i > 5).Select(i => i*i);
var isEqual = "this string".Equals("other string");
This rule doesn’t report issues on method calls with out or ref arguments.