A struct is a value type in C#. Value types have to have a fixed size, so
you're out of luck if you want to keep a variable-length array in the
struct. Your options as I see them:
1. Change from a struct to a class.
2. Keep TwEnumeration as a struct, but don't store ItemList as an array;
store it as a reference to a managed array. You'll have to use explicit
reference syntax (with & signs and stuff), and you'll have to go to extra
work to make sure that ItemList is set to a valid array reference, etc.
3. Make ItemList bigger than you think you'll need, like 100 elements or
something. Yes this wastes memory, but hey, RAM is cheap, right? Of course
this is not really a solution, but might work if you know that there's some
upper bounds on the number of results you'll ever need to store.
"Mateusz [PEYN] Adamus" <pe************ @tlen.pl> wrote in message
news:d1******** **@nemesis.news .tpi.pl...
Hi.
I have a problem. I'm creating a structure - looks like this:
<c#>
[StructLayout(La youtKind.Sequen tial, Pack=2)]
internal struct TwEnumeration
{
public ushort ItemType;
public uint NumItems;
public uint CurrentIndex;
public uint DefaultIndex;
[MarshalAs(Unman agedType.ByValA rray, SizeConst=10)]
public short[] ItemList;
}
</c#>
It works OK but I have a problem with it:
1. How can I make its size flexible? Now if I'll get 11 results they wan't
fit into an array. And if I'll get 9 results one field in array will be
blank. How can I declare a dynamic array?
2. Can I put there an Array type? If so how? :-)
TIA
best regards
Mateusz [PEYN] Adamus