[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!
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.
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];
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.
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/
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!