Struct within Struct, able to change inner Struct type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • metalheadstorm
    New Member
    • Sep 2007
    • 84

    Struct within Struct, able to change inner Struct type

    There isn't much explaining to this, this is what I have:

    Code:
     
        public struct PACKET_HEADER
        {
            public string computerIp;
            public string computerName;
            public string computerCustomName;
        };
    
        public struct PACKET
        {
            public PACKET_HEADER pktHdr;
            public PACKET_DATA pktData;
        };
    
    
        public struct PACKET_DATA
        {
            public Command command;
            public string data;  
        };
    
        public struct DATA_MESSAGE
        {
            public string message;
        };
    
        public struct DATA_FILE
        {
            public string fileName;
            public long fileSize;       
        };
    Basically I want the data field in PACKET_DATA to be able to be either DATA_FILE or DATA_MESSAGE. I know the type needs to be changed but I don't know what to, is generics an option?

    the end result should be so that I can do either:

    pktData.data.fi leName
    or
    pktData.data.me ssage
  • metalheadstorm
    New Member
    • Sep 2007
    • 84

    #2
    Solved please see: http://stackoverflow.com/questions/4...er-struct-type

    Comment

    Working...