Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best way to re-factor
Message
De
14/02/2013 13:20:08
 
 
À
14/02/2013 12:46:20
John Baird
Coatesville, Pennsylvanie, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01565967
Message ID:
01566042
Vues:
48
>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; }
  }
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform