C
Clark008
Guest
Hi,
i'm hoping somebody can help me out with this problem which has got me stumped (still new to C#)
In my console application, ive created a class called Map which contains an array of structs.
To access this array from the main class which contains main(), i attempted to write 'get/set properties' for the array, but it seems to have gone horribly wrong
====================================================================
Here is the struct:
[FONT=Courier New, Courier, Monospace] struct positionStruct
{
public string location;
public int coordinateX;
public int coordinateY;
public int coordinateZ;
} [/FONT]
====================================================================
And here is the code in the class:
[FONT=Courier New, Courier, Monospace]public class Map
{
positionStruct [] positionArray = new positionStruct[100];
// PROPERTY WITH GET AND SET FOR ARRAY, WHICH I CAN'T GET TO WORK
public positionStruct PositionArray[int index]
{
get
{
return positionArray[index];
}
set
{
positionArray[index] = value;
}
}
}[/FONT]
=========================================================
When i try to compile, the get/set bit receives a ton of errors, (e.g. ';' expected, ']' expected, and so on) so that is clearly wrong.
I'd be grateful if someone could point me in the right direction as to how to write the property,
thanks in advance !
Tim
PS: in hindsight i realize i could probably write the program without resorting to an array of structs in a separate class, but now i'm determined to sort out this annoying problem!!
Continue reading...
i'm hoping somebody can help me out with this problem which has got me stumped (still new to C#)
In my console application, ive created a class called Map which contains an array of structs.
To access this array from the main class which contains main(), i attempted to write 'get/set properties' for the array, but it seems to have gone horribly wrong
====================================================================
Here is the struct:
[FONT=Courier New, Courier, Monospace] struct positionStruct
{
public string location;
public int coordinateX;
public int coordinateY;
public int coordinateZ;
} [/FONT]
====================================================================
And here is the code in the class:
[FONT=Courier New, Courier, Monospace]public class Map
{
positionStruct [] positionArray = new positionStruct[100];
// PROPERTY WITH GET AND SET FOR ARRAY, WHICH I CAN'T GET TO WORK
public positionStruct PositionArray[int index]
{
get
{
return positionArray[index];
}
set
{
positionArray[index] = value;
}
}
}[/FONT]
=========================================================
When i try to compile, the get/set bit receives a ton of errors, (e.g. ';' expected, ']' expected, and so on) so that is clearly wrong.
I'd be grateful if someone could point me in the right direction as to how to write the property,
thanks in advance !
Tim
PS: in hindsight i realize i could probably write the program without resorting to an array of structs in a separate class, but now i'm determined to sort out this annoying problem!!
Continue reading...