title: Best practice of using the "out" keyword in C#
body: <p>I'm trying to formalise the usage of the "out" keyword in c# for a project I'm on, particularly with respect to any public methods. I can't seem to find any best practices out there and would like to know what is good or bad.</p>
  
  <p>Sometimes I'm seeing some methods signatures that look like this:</p>
  
  <pre><code>public decimal CalcSomething(Date start, Date end, out int someOtherNumber){}
  </code></pre>
  
  <p>At this point, it's just a feeling, this doesn't sit well with me. For some reason, I'd prefer to see:</p>
  
  <pre><code>public Result CalcSomething(Date start, Date end){}
  </code></pre>
  
  <p>where the result is a type that contains a decimal and the someOtherNumber. I think this makes it easier to read. It allows Result to be extended or have properties added without breaking code. It also means that the caller of this method doesn't have to declare a locally scoped "someOtherNumber" before calling. From usage expectations, not all callers are going to be interested in "someOtherNumber".</p>
  
  <p>As a contrast, the only instances that I can think of right now within the .Net framework where "out" parameters make sense are in methods like TryParse(). These actually make the caller write simpler code, whereby the caller is primarily going to be interested in the out parameter. </p>
  
  <pre><code>int i;
  if(int.TryParse("1", i)){
    DoSomething(i);
  }
  </code></pre>
  
  <p>I'm thinking that "out" should only be used if the return type is bool and the expected usages are where the "out" parameters will always be of interest to the caller, by design. </p>
  
  <p>Thoughts?</p>