3
我有這個屬性如何提取屬性重構
public List<PointK> LineList
{get;set;}
凡PointK
包括以下結構:
string Mark{get;set;}
double X{get;set;}
doible Y{get;set;}
現在,我有以下代碼:
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;
}
如何重構上述代碼?