[英]C# casting generic class with an interface as placeholder
我有以下類/接口:
public interface IConvexPolygon<T> where T : IPositionable
{
IEnumerable<FPVector2> UniqueAxes { get; }
IEnumerable<T> CornerPositionsClockwise { get; }
}
public class ConvexPolygon<T> : ConvexShape, IConvexPolygon<T> where T : IPositionable
{
...
}
public struct Positionable : IPositionable
{
...
}
我現在想將一個ConvexPolygon<Positionable>
轉換為IConvexPolygon<IPositionable>
以便能夠使用它的吸氣劑。 這會引發無效的強制轉換異常。 我嘗試在 IConvexPolygon 接口中使用out
指定協方差,結果相同
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.