Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Best way to re-factor
Message
From
14/02/2013 13:20:08
 
 
To
14/02/2013 12:46:20
John Baird
Coatesville, Pennsylvania, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01565967
Message ID:
01566042
Views:
49
>No, it has its place, I guess, but it could just as easily have returned an object with 2 properties.

Don't see that as being so elegant. Compare:
internal class Program
  {
    private static void Main()
    {
      string s = "123";
      int i;
      if (!int.TryParse(s, out i))
      {
        //error
      }

      TryParseReturnObject ret = JohnsTryParse(s);
      if (!ret.success)
      {
        //Error
      }
      i = ret.result;
    }

    private static TryParseReturnObject JohnsTryParse(string s)
    {
      int result;
      bool success = int.TryParse(s, out result);
      return new TryParseReturnObject{result = result,success = success};
    }
  }

  public class TryParseReturnObject
  {
    public int result { get; set; }
    public bool success { get; set; }
  }
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform