c# - How to specify a class that may contain another class -


i want create class have class second class may different each time first class called. 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 call serverresponseobject different objects each time, once tvchannelobject , once channelcategoryobject?

what you're looking generic type parameter:

public class serverresponseobject<t> {     public serverresponseobject(t obj)     {         obj = obj;     }      public t obj { get; set; } } 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -