[英]How to specify a class that may contain another class
I want to create a class that have a class but this second class may be different each time the first class is called. 我想创建一个具有类的类,但每次调用第一个类时,第二个类可能不同。 For example:
例如:
public class ServerResponseObject
{
public string statusCode { get; set; }
public string errorCode { get; set; }
public string errorDescription { get; set; }
public Object obj { get; set; }
public ServerResponseObject(Object obje)
{
obj = obje;
}
}
public class TVChannelObject
{
public string number { get; set; }
public string title { get; set; }
public string FavoriteChannel { get; set; }
public string description { get; set; }
public string packageid { get; set; }
public string format { get; set; }
}
public class ChannelCategoryObject
{
public string id { get; set; }
public string name { get; set; }
}
How can I do it to call the ServerResponseObject
with different objects each time, once with TVChannelObject
and once with ChannelCategoryObject
? 我怎样才能每次使用不同的对象调用
ServerResponseObject
,一次使用TVChannelObject
,一次使用ChannelCategoryObject
?
What you're looking for is a generic type parameter : 您正在寻找的是泛型类型参数 :
public class ServerResponseObject<T>
{
public ServerResponseObject(T obj)
{
Obj = obj;
}
public T Obj { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.