Hi i'd like to know if its possble to make getters and setters for arrays? I know how to do it one by one.. but its an array of 50 variables. Is there any shorter method?
thanks
Hi i'd like to know if its possble to make getters and setters for arrays? I know how to do it one by one.. but its an array of 50 variables. Is there any shorter method?
thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Felipe MarksPosted Aug 20, 2007, 7:29 AM
thanx Alan
That sounds good
AlanPosted Aug 20, 2007, 7:23 AM
I've just thought of another way to have a 'named' array which would be to index it using an enum in which you define constants having values from 0 to 49.
So, if Fred corresponded to a value of 7 in your array then,as an alternative to using:
myArray[7]
you could use:
myArray[(int)MyEnum.Fred]
It's a nuisance having to cast the enum value to int but there doesn't seem to be a way around this.
AlanPosted Aug 20, 2007, 6:46 AM
The only way I can think of to do this would be to wrap the array in a custom class with 50 read/write properties to get/set each element of the array.
However, rather than use an array it might be better to use a Hashtable. You can then define a string key for each element you add and retrieve those elements by key rather than by position.