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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
AlanRank #669 · 3.6K reputationPosted Aug 20, 2007, 2:46 AM EDT
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.
AlanRank #669 · 3.6K reputationPosted Aug 20, 2007, 3:23 AM EDT
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.
Felipe Marks72 reputationPosted Aug 20, 2007, 3:29 AM EDT
thanx Alan
That sounds good