473,403 Members | 2,338 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,403 software developers and data experts.

Struct array

7
Hi,
I have an enum, struct has one enum and a string and I have an array of struct like this in C# ---

public enum ENU : int
{
eval1=1,
eval2
}

public strut STRU //Struct has a enum and a string
{
public ENU senu;
string sstr;
public STRU (ENU cenu, string cstr) //Constructor for struct
{
senu=cenu;
sstr=cstr;
}
}
STRU stru0= new STRU(ENU.eval1, "Hello") //Create strucs as this
STRU stru1 = new STRU(ENU.eval2, "World")
//Array of struct

STRU[] arrstru= new STRU[2];
arrstru[0]=stru0;
arrstru[1]=stru1;

Till this there are no errors in the code. I want to use foreach on this array and fill the combo box with enum data. foreach is giving me errors. Can anybody help me writing foreach for this strut array?

thanks for help
newP
}
Jul 29 '07 #1
5 1549
kenobewan
4,871 Expert 4TB
Wecome to TSDN. Please display how you tried to do it and the error you received. Thanks.
Jul 29 '07 #2
newP
7
please refer to the post below.
newP
Jul 29 '07 #3
newP
7
All the enum,struct definitions are in program.cs (default in 2005--which has static void main()) just after namespace declaration but before main(). array declaration and definition is in main().
function to fill combo box is in frmcombo.cs inside the partial class. like this

public partial class frmcombo : Form
{
public frmcombo()
{
InitializeComponent();
this.fillcombo(); //function call
}

public void fillcombbo() //Fill the data in command combo box
{
foreach(struct STRU in arrstru) //errors 1,2,3,4,5,6,7
{
//loop thru each structure to fill in combo box
}
}

}

errors are :
1. Error { expected
2. Error } expected
3.Error 3 Invalid token 'in' in class, struct, or interface member
4. Error 4 Invalid token ')' in class, struct, or interface member
5. Error 5 Type expected
6.Error 6 ) expected
7. Error 7 ; expected


I don't know what is wrong.

Please help!!!

Thanks,
newP
Wecome to TSDN. Please display how you tried to do it and the error you received. Thanks.
Jul 29 '07 #4
kenobewan
4,871 Expert 4TB
Most of them seem to simply coding errors. I suggest cleaning these up and then debug. HTH.
Jul 29 '07 #5
RoninZA
78
Hi New P -

I can see the problem in your code... your foreach declaration is incorrect, what you need to do is change it as follows:
Expand|Select|Wrap|Line Numbers
  1. foreach(STRU item in arrstru) //errors 1,2,3,4,5,6,7
  2. {
  3.     //loop thru each structure to fill in combo box, using the item variable
  4. }
  5.  
That should sort out your problem! The compiler thinks that you are trying to define a new struct when you say foreach (struct STRU...), what it needs is to be told what object type is being iterated, instead of defining a new one :)

Hope this helps!
Jul 30 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Stuart Norris | last post by:
Dear Readers, I am attempting to initialise a struct contiaing a dynamic character string. In the example below I am trying to initialise the name field so that my struct does not waste space. ...
19
by: Geetesh | last post by:
Recently i saw a code in which there was a structer defination similar as bellow: struct foo { int dummy1; int dummy2; int last }; In application the above array is always allocated at...
20
by: fix | last post by:
Hi all, I feel unclear about what my code is doing, although it works but I am not sure if there is any possible bug, please help me to verify it. This is a trie node (just similar to tree nodes)...
2
by: beetle | last post by:
Hello, I'm storing data in several different binary tree's. The root node is located in a struct containing general data about the tree. struct lnode { char *fname; int nentry;
4
by: PCHOME | last post by:
Hi! I have questions about qsort( ). Is anyone be willing to help? I use the following struct: struct Struct_A{ double value; ... } *AA, **pAA;
5
by: Cybertof | last post by:
Hello, Is it possible to convert a VB6 Array of Struct to a C# Array Of Struct ? The test context is a C# application calling a VB6 ActiveX DLL Function using UDT (User Defined Type) and...
3
by: GrkEngineer | last post by:
I recently had to use someone's struct from a native app to receive data over Udp. The struct has a array member which looked like this: struct sensorHdr{ char sName; }; When I tried to make...
4
by: DaHool | last post by:
Hi there !!! I browsed around the Internet in search for a solution of a little difficult problem i have in VB.NET.... However, i cannot find a suitable anwser anywhere, so i thought i'll give...
9
by: AM | last post by:
Hi, I have a C++ Dll that has a function that is being exported as shown below extern "C" __declspec(dllexport) validationResult __stdcall _validateData(double dataToMat, int time); A...
11
by: abhiM | last post by:
I have a struct that has an array in it. I need to assign space to the array in a function and pass the corresponding struct by reference to another function so that it can store values into the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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.