Question Choose single property from array

bufer24

Active member
Joined
Mar 27, 2008
Messages
35
Programming Experience
3-5
Hello, please, I want to do the following: I have an object (class) that has a property called Languages which sets or returns an array of strings. Now I want do add another property (let´s call it SelectedLanguage) that selects a single string from the existing Languages array? Is it possible to construct such a property?
 
Yes, add a String property and only allow to set if your array contains value. The setter could be like this:
VB.NET:
If Array.IndexOf(Languages, value) <> -1 Then
    Me._selectedlang = value
End If
If you mean the property should give the options available, then that is only possible with Enum types.
 
Thanks, I´ll give it a try. Enums are good to choose a property value from several possible values. But I can´t change Enum items at runtime, can I?
 
Thanks, I´ll give it a try. Enums are good to choose a property value from several possible values. But I can´t change Enum items at runtime, can I?

No, but then the languages in the world don't really change that rapidly so you wouldnt really need to edit your enum. However, if you intend to provide an ability for someone to translate your app into a custom language, using a string would probably be better than an enum
 
Back
Top