【发布时间】:2012-01-23 15:56:38
【问题描述】:
复制问题的一些代码:
using System;
public abstract class Response { }
public abstract class Request<T> where T : Response { }
public class LoginResponse : Response { }
public class LoginRequest : Request<LoginResponse> { }
public class Program
{
static void Main(string[] args)
{
LoginRequest login = new LoginRequest();
/* Error: Cannot implicitly convert type 'LoginRequest' to 'Request' */
Request<Response> castTest = login;
/* No Error */
Request<LoginResponse> castTest2 = login;
}
}
据我所知,LoginRequest 类是 Request
注意:我也尝试过显式转换
【问题讨论】:
标签: c# inheritance abstract-class