我相信我错过了一些简单的东西,但是我正在尝试将一个强类型对象列表转换为一个该接口类型的列表。
下面是一个示例,用于演示错误:
public void ExampleCode(){
List<Cube> cubes = new List<Cube>();
List<Shape> allShapes;
allShapes = cubes;//Syntax Error
allShapes = (List<Shape>)cubes;//Syntax Error
}
public class Cube : Shape
{
public int ID { get; set; }
public int Sides { get; set; }
}
public interface Shape
{
int ID { get; set; }
int Sides { get; set; }
}