Help! How to write 'get''set' property for an array of structs?

  • Thread starter Thread starter Clark008
  • Start date Start date
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
smile_confused.gif


====================================================================
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 !
smile_regular.gif




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!!
smile_angry.gif


Continue reading...
 
Back
Top