title: What is the perfect way to write "return" in a method
body: <p>I don't like methods have several return lines. So I created a return value with string result - and in every condition I write result = something... </p>
  
  <p>But when I write "try-catch" mechanism, I have to set <em>public string result</em>. Because, if I return a result in try, compiler will launch error, and says not all codes have return value. If I write <em>result = string.Empty</em> to end of the method, resharper says, it's not reachable code. So, here an example, and here is my question;</p>
  
  <p><strong>"What is the perfect way to write "return" in a method ?"</strong></p>
  
  <pre><code>    public static string PingThatAddress(string hostAddress)
      {
          try
          {
              Ping ping = new Ping();
              PingReply pingreply = ping.Send(hostAddress);
  
              string result;
              if (pingreply != null &amp;&amp; pingreply.Status.ToString() != "TimedOut")
              {
                  result = "Address: " + pingreply.Address + "\r"
                       + "Roundtrip Time: " + pingreply.RoundtripTime + "\r"
                       + "TTL (Time To Live): " + pingreply.Options.Ttl + "\r"
                       + "Buffer Size: " + pingreply.Buffer.Length + "\r";
              }
              else
              {
                  result = string.Empty;
              }
  
              return result;
          }
          catch (Exception pingError)
          {
              Debug.Fail(pingError.Message + " " + pingError);
          }
          //compiler error: THERE IS NO RETURN VALUE here?
      }
  </code></pre>