|
-
September 21st, 2011, 09:42 AM
#1
[RESOLVED] VS2010/.Net4 Need help setting up a structure
Hello!
I'm having trouble with the FieldData[] part.
Here is a code segment:
Code:
public struct dataObj
{
string Delimiter;
string[] FieldData = new string[128];
int NumberOfFields;
string TxString;
int TransmitInterval;
}
public dataObj MyDataObj = new dataObj
I need to be able to use the structure like this:
Code:
MyDataObj.Delimiter = ",";
MyDataObj.FieldData[0] = "555";
MyDataObj.FieldData[1] = "543";
...
...
MyDataObj.FieldData[n] = "xxx";
MyDataObj.NumberOfFields = 10;
Can someone show me how to do this?
I can do this using a VisualBasic method, but I am trying to avoid this if possible.
Thanks!
-
September 21st, 2011, 12:10 PM
#2
Re: VS2010/.Net4 Need help setting up a structure
So what is the problem you are having? Hard to help if you don't tell us what kind of problem you are having.
Always use [code][/code] tags when posting code.
-
September 21st, 2011, 12:17 PM
#3
Re: VS2010/.Net4 Need help setting up a structure
Sorry about that!
I'm getting an error even before I try to compile/execute.
'cannot have instance field initializers in structs'
This line of code gives the error, however, when outside of the structure, it works just fine.
Code:
string[] FieldData = new string[128];
-
September 21st, 2011, 01:41 PM
#4
Re: VS2010/.Net4 Need help setting up a structure
You should create a class rather than a structure. Then create an instance of the class at what ever level you need to use it.
Always use [code][/code] tags when posting code.
-
September 21st, 2011, 03:35 PM
#5
Re: VS2010/.Net4 Need help setting up a structure
I've never had the need to do this, so I don't have a wealth of knowlege to help you out, but I did run accross what seems to be an interesting page covering your topic.
http://www.developerfusion.com/artic...-structs-in-c/
-
September 21st, 2011, 04:14 PM
#6
Re: VS2010/.Net4 Need help setting up a structure
DataMiser,
I'm just an old hack trying to make it in the .Net world!
That was the solution!
Thanks for your help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|