Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I create a static array of structure?

5 views
Skip to first unread message

A Nonymous

unread,
May 31, 2007, 11:37:48 AM5/31/07
to
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.

Marc Rohloff [TeamB]

unread,
May 31, 2007, 9:12:16 PM5/31/07
to
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

A Nonymous

unread,
Jun 1, 2007, 11:07:42 AM6/1/07
to
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.

0 new messages