CA1806: Do not ignore method results
There are several possible reasons for this warning:
A new object is created but never used.
A method that creates and returns a new string is called and the new string is never used.
A COM or P/Invoke method that returns a HRESULT or error code that is never used. Rule Description
Unnecessary object creation and the associated garbage collection of the unused object degrade performance.
Strings are immutable and methods such as String.ToUpper returns a new instance of a string instead of modifying the instance of the string in the calling method.
Ignoring HRESULT or error code can lead to unexpected behavior in error conditions or to low-resource conditions.
If method A creates a new instance of B object that is never used, pass the instance as an argument to another method or assign the instance to a variable. If the object creation is unnecessary, remove the it.-or-
If method A calls method B, but does not use the new string instance that the method B returns. Pass the instance as an argument to another method, assign the instance to a variable. Or remove the call if it is unnecessary.
If method A calls method B, but does not use the HRESULT or error code that the method returns. Use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method.
The following example shows a class that ignores the result of calling String.Trim.
The following example fixes the previous violation by assigning the result of String.Trim back to the variable it was called on.
The following example shows a method that does not use an object that it creates.
This violation cannot be reproduced in Visual Basic.
The following example fixes the previous violation by removing the unnecessary creation of an object.
The following example shows a method that ignores the error code that the native method GetShortPathName returns.
The following example fixes the previous violation by checking the error code and throwing an exception when the call fails.