468,107 Members | 1,433 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,107 developers. It's quick & easy.

Struct within Struct, able to change inner Struct type

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

✓ answered by metalheadstorm


1 1290

Post your reply

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

Similar topics

3 posts views Thread by Serve Laurijssen | last post: by
2 posts views Thread by Walter Deodiaus | last post: by
5 posts views Thread by Johs32 | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.