is there a way to remove duplication in this code

Posted by oo on Stack Overflow See other posts from Stack Overflow or by oo
Published on 2010-04-25T16:37:24Z Indexed on 2010/04/25 16:43 UTC
Read the original article Hit count: 189

Filed under:
|

i have a method that looks like this:

   private double GetX()
    {
        if (Servings.Count > 0)
        {
            return Servings[0].X;
        }
        if (!string.IsNullOrEmpty(Description))
        {
            FoodDescriptionParser parser = new FoodDescriptionParser();
            return parser.Parse(Description).X;
        }
        return 0;
    }

and i have another method that looks like this:

  private double GetY()
    {
        if (Servings.Count > 0)
        {
            return Servings[0].Y;
        }
        if (!string.IsNullOrEmpty(Description))
        {
            FoodDescriptionParser parser = new FoodDescriptionParser();
            return parser.Parse(Description).Y;
        }
        return 0;
    }

is there anyway to consolidate this as the only thing different is the property names?

© Stack Overflow or respective owner

Related posts about code-duplication

Related posts about c#