How to Extract Properties for Refactoring

Posted by Ngu Soon Hui on Stack Overflow See other posts from Stack Overflow or by Ngu Soon Hui
Published on 2010-04-27T14:03:27Z Indexed on 2010/04/27 14:13 UTC
Read the original article Hit count: 341

Filed under:

I have this property

public List<PointK> LineList
{get;set;}

Where PointK consists of the following structure:

string Mark{get;set;}
double X{get;set;}
doible Y{get;set;}

Now, I have the following code:

   private static Dictionary<string , double > GetY(List<PointK> points)
    {
        var invertedDictResult = new Dictionary<string, double>();
        foreach (var point in points)
        {
            if (!invertedDictResult.ContainsKey(point.Mark))
            {
                invertedDictResult.Add(point .Mark, Math.Round(point.Y, 4));
            }

        }

        return invertedDictResult;
    }


   private static Dictionary<string , double > GetX(List<PointK> points)
    {
        var invertedDictResult = new Dictionary<string, double>();
        foreach (var point in points)
        {
            if (!invertedDictResult.ContainsKey(point.Mark))
            {
                invertedDictResult.Add(point .Mark, Math.Round(point.X, 4));
            }

        }

        return invertedDictResult;
    }

How to restructure the above code?

© Stack Overflow or respective owner

Related posts about c#