Thread View: borland.public.csharpbuilder.language.csharp
3 messages
3 total messages
Started by A Nonymous
Thu, 31 May 2007 15:37
How can I create a static array of structure?
Author: A Nonymous
Date: Thu, 31 May 2007 15:37
Date: Thu, 31 May 2007 15:37
26 lines
1750 bytes
1750 bytes
I am attempting to convert a C++ application to C#. In the application I
use a static array of structures to maintain a device capabilities matrix.
Basically I am communication with a series of devices across the internet.
All of the devices are these same but have minor differences based on model
and firmware revision. To keep it strait, in the C++ app I defined a
structure containing the variable parameters for a device. Then I created
a static array of this stricture which is populated with the appropriate
parameters for the model.
struct TWidget
{
int MemAvail;
int MemOffset;
};
static TWidget Widget[2] =
{
{0x100,0x200},
{0x120,0x400}
};
In my app I can just refer to Widget[Model].MemAvail which will give me
the amount of available memory for any model. When we release a new model,
I just add a new layer to the array...
How can I convert it to C#? So far I can find no syntax that works.
Re: How can I create a static array of structure?
Author: Marc Rohloff TeamB
Date: Fri, 01 Jun 2007 01:12
Date: Fri, 01 Jun 2007 01:12
42 lines
2061 bytes
2061 bytes
On 31 May 2007 08:37:48 -0700, A Nonymous wrote:
> struct TWidget
> {
> int MemAvail;
> int MemOffset;
> };
>
> static TWidget Widget[2] =
> {
> {0x100,0x200},
> {0x120,0x400}
> };
>
> In my app I can just refer to Widget[Model].MemAvail which will give me
> the amount of available memory for any model. When we release a new model,
> I just add a new layer to the array...
>
> How can I convert it to C#? So far I can find no syntax that works.
You could do something like:
struct TWidget
{
int MemAvail;
int MemOffset;
internal TWidget(int a, int o) { MemAvail = a; MemOffset = o;
}
};
class Program {
static TWidget[] Widget = {
new TWidget(1,2),
new TWidget(2,4)
};
--
Marc Rohloff [TeamB]
marc -at- marc rohloff -dot- com
Re: How can I create a static array of structure?
Author: A Nonymous
Date: Fri, 01 Jun 2007 15:07
Date: Fri, 01 Jun 2007 15:07
9 lines
1217 bytes
1217 bytes
Thanks, I will give it a shot, but I wish there were an easier way to implement a static data table. I use this a lot for lookup tables in conversion routines. What about some sort of constant declaration? As an alternative I am considering loading the tables from files, or possible program resources.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads