Is it necessarily bad style to ignore the return value of a method

Posted by Jono on Stack Overflow See other posts from Stack Overflow or by Jono
Published on 2010-04-29T08:14:30Z Indexed on 2010/04/29 8:17 UTC
Read the original article Hit count: 250

Filed under:
|

Let's say I have a C# method

public void CheckXYZ(int xyz) {
  // do some operation with side effects
}
Elsewhere in the same class is another method
public int GetCheckedXYZ(int xyz) {
  int abc;
  // functionally equivalent operation to CheckXYZ, 
  // with additional side effect of assigning a value to abc
  return abc; // this value is calculated during the check above
}
Is it necessarily bad style to refactor this by removing the CheckXYZ method, and replacing all existing CheckXYZ() calls with GetCheckedXYZ(), ignoring the return value? The returned type isn't IDisposable in this case. Does it come down to discretion?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET