Private and Public Properties of type Array 
Author Message
 Private and Public Properties of type Array

OK, Here's the gist of what I'm trying to do. I'm writing a fantasy
roleplaying game character generator/tracker application. I created a class
library called Item to handle basic inventory for the character. In this
class I have a property called UseableBy which I am wanting to create as a
1-dimensional 3-element array of type String. The first element determines
what character classes can use the item (fighter, thief, wizard, etc.), the
second determines what races can use it (human, elf, dwarf, etc.), and the
third determines what alignments can use it (good, neutral, evil, etc.).

The private property declaration is as follows:

' Initializes array as an empty 3 element array of strings
Private m_arrUseableBy() As String = {"", "", ""}

Furthur on down in the public property section is where I'm getting tangled
up

Public Property UseableBy() As String
    Get
        Return m_arrUseableBy..ToString
    End Get
    Set(ByVal Value As String)
        m_arrUseableBy = Value
    End Set
End Property

I know my problem with mixing the two (private as array of string and public
as string) is what's causing the foul up. Is there any way to declare the
public property as an array of strings so the get and set will match the
private property? I have spent hours pouring through the help files with no
success. All the books I can find just tell me how to declare and initialize
the array as a normal variable.

Dim StringArray(2) As String
Dim StringArray() As String = {"abc", "xyz", "123"}

And so on and so on.

How do I declare a Public Property of type Array? Specifically a
1-dimensional, 3-element Array of type String?

Jeff Cox



Wed, 29 Dec 2004 07:04:12 GMT  
 Private and Public Properties of type Array
Jeff,

Quote:
>How do I declare a Public Property of type Array? Specifically a
>1-dimensional, 3-element Array of type String?

Public Property UseableBy As String()
...
  Set(ByVal value As String())
...

That will give you a 1-dimensional String array property. The fact
that it must have 3 elements is something you'll have to check
manually in the Set accessor.

Mattias

===
Mattias Sj?gren (VB MVP)

http://www.msjogren.net/dotnet/



Wed, 29 Dec 2004 09:42:22 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Best Practice: Referring to Public Properties or Private Variables

2. How: Public Read Only / Private Write Property?

3. Public and private properties URGENT

4. Public and private properties URGENT

5. Placing an control in a class module as public or private property

6. Type mismatch in a private array defined in a class

7. How to make a array an private property???

8. Type Mismatch when adding Public Property or Event

9. Allowed Public Property Get Data Types?

10. User Defined Type as a public property

11. Objects with arrays as public properties

12. Convert array of value type to array of reference type

 

 
Powered by phpBB® Forum Software