Array in struct

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2006
Posts: 21
Reputation: hkBattousai is an unknown quantity at this point 
Solved Threads: 0
hkBattousai's Avatar
hkBattousai hkBattousai is offline Offline
Newbie Poster

Array in struct

 
0
  #1
Feb 10th, 2007
I have this C++ code :
  1. const int ANYSIZE_ARRAY = 1;
  2. struct LUID {DWORD LowPart; WORD HighPart;};
  3. struct LUID_AND_ATTRIBUTES {LUID Luid; DWORD Attributes;};
  4. struct TOKEN_PRIVILEGES {DWORD PrivilegeCount; LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY];};
I want to convert this code into C# syntax.

I tried this one, but don't know how to place array in a struct.
  1. const int ANYSIZE_ARRAY = 1;
  2. struct LUID {Int32 LowPart; Int16 HighPart;};
  3. struct LUID_AND_ATTRIBUTES {LUID Luid; Int32 Attributes;};
  4. struct TOKEN_PRIVILEGES {Int32 PriviligeCount; /*WHAT TO WRITE HERE??*/};
Help me please.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 29
Reputation: brainbox is an unknown quantity at this point 
Solved Threads: 1
brainbox's Avatar
brainbox brainbox is offline Offline
Light Poster

Re: Array in struct

 
0
  #2
Feb 10th, 2007
Hi

Would it not be something like;

LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY];


for the above i have assumed that, you want an array of LUID_AND_ATTRIBUTES type struct , which you have defined before, as comprising of LUID Luid; int32 Attributes.
If my assunption is wrong, then please accept my apologies.

HTH

Thanks

Originally Posted by hkBattousai View Post
I have this C++ code :
  1. const int ANYSIZE_ARRAY = 1;
  2. struct LUID {DWORD LowPart; WORD HighPart;};
  3. struct LUID_AND_ATTRIBUTES {LUID Luid; DWORD Attributes;};
  4. struct TOKEN_PRIVILEGES {DWORD PrivilegeCount; LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY];};
I want to convert this code into C# syntax.

I tried this one, but don't know how to place array in a struct.
  1. const int ANYSIZE_ARRAY = 1;
  2. struct LUID {Int32 LowPart; Int16 HighPart;};
  3. struct LUID_AND_ATTRIBUTES {LUID Luid; Int32 Attributes;};
  4. struct TOKEN_PRIVILEGES {Int32 PriviligeCount; /*WHAT TO WRITE HERE??*/};
Help me please.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 21
Reputation: hkBattousai is an unknown quantity at this point 
Solved Threads: 0
hkBattousai's Avatar
hkBattousai hkBattousai is offline Offline
Newbie Poster

Re: Array in struct

 
0
  #3
Feb 11th, 2007
Originally Posted by brainbox View Post
Would it not be something like;
LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY];
Given error :
  1. Error 1 Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type. C:\Prog\SAVE\C#\Shutdown\Main.cs 22 86 Shutdown
  2. Error 2 Array size cannot be specified in a variable declaration (try initializing with a 'new' expression) C:\Prog\SAVE\C#\Shutdown\Main.cs 22 87 Shutdown
  3.  
Originally Posted by brainbox View Post
for the above i have assumed that, you want an array of LUID_AND_ATTRIBUTES type struct , which you have defined before, as comprising of LUID Luid; int32 Attributes.
Exactly. What I try to do is place an array into a struct. I couldn't find an example not even in google.

This one doesn't work :
  1. struct Animals { float Bird; int Rabbit[20]; Int64 Elephant; };
Error 1 Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type. C:\Prog\SAVE\C#\Shutdown\Main.cs 35 42 Shutdown
Error 2 Array size cannot be specified in a variable declaration (try initializing with a 'new' expression) C:\Prog\SAVE\C#\Shutdown\Main.cs 35 43 Shutdown

This one too :
  1. struct Animals { float Bird; int[20] Rabbit; Int64 Elephant; };
Error 1 Array size cannot be specified in a variable declaration (try initializing with a 'new' expression) C:\Prog\SAVE\C#\Shutdown\Main.cs 35 36 Shutdown

Another one :
  1. struct Animals { float Bird; int Rabbit[]; Int64 Elephant; };
Error 1 Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type. C:\Prog\SAVE\C#\Shutdown\Main.cs 35 42 Shutdown

This one works :
  1. struct Animals { float Bird; int[] Rabbit; Int64 Elephant; };
But now I am not able to specify the size of the array


Any suggestions?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC