using System;
class X {}
class Y: X {}
class Wrapper<T> where T : X {}
public class HelloWorld
{
public static void Main(string[] args)
{
Wrapper<Y> y = new();
Wrapper<X> x = y; // Error here
}
}
错误为error CS0029: Cannot implicitly convert type 'Wrapper<Y>' to 'Wrapper<X>'
这里我想把Wrapper<Y>
转换成Wrapper<X>
.
我怎么能这样做呢?