一个简单的泛型问题 /// <summary>
/// 实体类
/// </summary>
public class Entity
{
public int ID;
}
/// <summary>
/// 客户类继承实体
/// </summary>
public class Customer : Entity
{
public string Name;
public int age;
}
public class Operate<T> where T : Entity
{
public Operate()
{ }
public void Print()
{
Console.Write("Test");
}
}
public class TestClass
{
public TestClass()
{
//这样赋值是有问题的,因为Entity是基类,Customer是子类,能否通过何种方式进行赋值呢? (问题)
Operate<Entity> O = new Operate<Customer>(); --如何做才能
}
}