長方形と円の2つの形状のリストがあります。これらは両方とも、ID、タイプ、および境界の3つの共通のプロパティを共有します。
円には、範囲と中心の2つの追加プロパティがあります
各タイプのリストを1つのリストに結合して、それらを反復処理できるようにするには、2つのforeachサイクルを入力する必要がありません。
これは、リストを組み合わせるよりも良い方法で行うことができますか?
public interface IRectangle
{
string Id { get; set; }
GeoLocationTypes Type { get; set; }
Bounds Bounds { get; set; }
}
public class Rectangle : IRectangle
{
public string Id { get; set; }
public GeoLocationTypes Type { get; set; }
public Bounds Bounds { get; set; }
}
public interface ICircle
{
string Id { get; set; }
GeoLocationTypes Type { get; set; }
Bounds Bounds { get; set; }
float Radius { get; set; }
Coordinates Center { get; set; }
}
public class Circle : ICircle
{
public string Id { get; set; }
public GeoLocationTypes Type { get; set; }
public Bounds Bounds { get; set; }
public float Radius { get; set; }
public Coordinates Center { get; set; }
}
public class Bounds
{
public Coordinates NE { get; set; }
public Coordinates SW { get; set; }
}
public class Coordinates
{
public float Lat { get; set; }
public float Lng { get; set; }
}