Skip to content

Gendarme.Rules.Performance.DoNotIgnoreMethodResultRule(git)

Sebastien Pouliot edited this page Mar 2, 2011 · 1 revision

DoNotIgnoreMethodResultRule

Assembly: Gendarme.Rules.Performance
Version: git

Description

This rule fires if a method is called that returns a new instance but that instance is not used. This is a performance problem because it is wasteful to create and collect objects which are never actually used. It may also indicate a logic problem. Note that this rule currently only checks methods within a small number of System types.

Examples

Bad example:

public void GetName ()
{
    string name = Console.ReadLine ();
    // This is a bug: strings are (mostly) immutable so Trim leaves
    // name untouched and returns a new string.
    name.Trim ();
    Console.WriteLine ("Name: {0}", name);
}

Good example:

public void GetName ()
{
    string name = Console.ReadLine ();
    name = name.Trim ();
    Console.WriteLine ("Name: {0}", name);
}

Source code

You can browse the latest source code of this rule on github.com

Clone this wiki locally