TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C# Coding Standard

Rule:  7@700

Synopsis:Do not ignore method results
Severity Level:4
Category:Object oriented


There are several situations in which ignoring results is not desired:

  • A new object is created but never used. Unnecessary object creation and the associated garbage collection of the unused object degrade performance.
  • A method that creates and returns a new string is called and the new string is never used. 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.
  • A COM or P/Invoke method that returns a HRESULT or error code that is never used. Ignoring HRESULT or error code can lead to unexpected behavior in error conditions or to low-resource conditions.

If the method result is never going to be used, then the design of the method is incorrect. In that case the return type should be set to void instead.