By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,359 Members | 1,481 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,359 IT Pros & Developers. It's quick & easy.

Struct within Struct, able to change inner Struct type

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

Expand|Select|Wrap|Line Numbers
  1.  
  2.     public struct PACKET_HEADER
  3.     {
  4.         public string computerIp;
  5.         public string computerName;
  6.         public string computerCustomName;
  7.     };
  8.  
  9.     public struct PACKET
  10.     {
  11.         public PACKET_HEADER pktHdr;
  12.         public PACKET_DATA pktData;
  13.     };
  14.  
  15.  
  16.     public struct PACKET_DATA
  17.     {
  18.         public Command command;
  19.         public string data;  
  20.     };
  21.  
  22.     public struct DATA_MESSAGE
  23.     {
  24.         public string message;
  25.     };
  26.  
  27.     public struct DATA_FILE
  28.     {
  29.         public string fileName;
  30.         public long fileSize;       
  31.     };
  32.  
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.fileName
or
pktData.data.message
Dec 20 '10 #1

Share this Question
Share on Google+
1 Reply

Post your reply

Sign in to post your reply or Sign up for a free account.