I have lists of two Shapes – Rectangles and Circles.
They both share 3 common properties – ID , Type and Bounds
Circles have 2 extra properties – Range and Center
How can i join lists of each type into a single list so i can iterate over them so i don’t have to type two foreach cycles
Could this be donne in a better way than combining the lists ?
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; }
}
Make both
IRectangleandICircleinherit from a shared type – sayIShape.A
List<IShape>will then be able to take anyIRectangleandICircletypes and their inheriting types.Since both
IRectangleandICircleshare a number of properties, you can do this: