473,399 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

C# - initializing an array within a structure?

Using C#...
I am pulling shared memory in to my app that is in the form of apredefined structure. I have arrays in 2 sub-structures. Onearray is an array of another predefined structure, and the otheris simply an array of ushort's.
Such as:

public struct predefinedStruct {
public ushort a;
public ushort b;
}

public struct struct1 {
public int blah1;
public int blah2;
public predefinedStruct [] ARRAY1; // <-- size = 6
}

public struct struct2 {
public ushort blah1;
public ushort blah2;
public ushort [] ARRAY2; // <-- size = 32
}

...

for my pointer to this structure in memory to match thispredefined structure in my code, I need the size of my structurein my code to match the size of the structure in memory. Sotherefore I need to initialize my arrays. But I can't seem toinit them in the struct.

How can I initialize my two arrays, ARRAY1, and ARRAY2, in thiscase? The size of each array is:
ARRAY1 = 6 elements
ARRAY2 = 32 elements
--------------------------------
From: Doug C
--------------------------------
From: Doug C

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>WgwdRHYfKE+hgFBFJYm1hw==</Id>
Jul 21 '05 #1
1 8123
You can do it one of 2 ways, make it a class or provide a parameterized
constructor. I know the length is predefined, but can you just accept the
length anyway?

public struct struct1 {
public int blah1;
public int blah2;
public predefinedStruct [] ARRAY1; // <-- size = 6

public struct1(int iSize)
{
ARRAY1 = predefinedStruct[iSize];
}
}

--
Eric Marvets
Principal Consultant

the bang project

<shameless self promotion>

Email sa***@bangproject.com for Information on Our Architecture and
Mentoring Services

</shameless self promotion>
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Bart Goeman | last post by:
Hi, I have a question about how to put redundant information in data structures, initialized at compile time. This is often necessary for performance reasons and can't be done at run time (data...
2
by: Steve | last post by:
I have defined a structure of; Private Structure Menu Private MenuID as string Private Label as string End Structure ....and I would like to create and initialize an array of type "Menu". I...
1
by: Doug C via .NET 247 | last post by:
Using C#... I am pulling shared memory in to my app that is in the form of apredefined structure. I have arrays in 2 sub-structures. Onearray is an array of another predefined structure, and the...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
7
by: Paminu | last post by:
In the following code I am trying to initialize a pointer that is located in a struct. #include <stdlib.h> #include <stdio.h> #define KIDS 4 typedef struct test { void *content;
12
by: Mik0b0 | last post by:
Hallo. Let's say, there is a structure struct struct10{ int a1; int a2; int a3; int a4; }count={ {10,20,30,40}, {50,60,70,80}
4
by: benn686 | last post by:
I have a structure that contains a union that Id like to initialize at compile time... something like: //global declare and initialize fullStructType var1 = { unionMember.union1.field1...
5
by: hankypan1 | last post by:
Hi All, I need a tree data structure for my application. It is the non -cyclic simple tree where i can have any number of children node and each child can recursively become a sub tree like a...
2
by: Martin Payne | last post by:
I am trying to initialise a structure with random values for all its fields. It is a large structure so I do not want to do it for each element in turn (it would take ages). Please note my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.