Question Intellisense entering type rather than value

njsokalski

Well-known member
Joined
Mar 16, 2011
Messages
102
Programming Experience
5-10
I have a class that has a property declared as follows:

Public Property Position As Byte()

Very simple property, nothing complicated. However, in Visual Studio 2010 when accessing this property, I type the following (temp is just the name of a variable):

temp.Position(1)

but Visual Studio 2010 enters the following code:

temp.Position(Int16)

It's like Intellisense wants to use Int16 instead of 1, but the property is an array, so why would it not want me to put an index? Why is it doing this, and how can I fix it? Thanks.
 
When you get a property value you are actually calling a method, the properties Get method, so intellisense interprets the opening paranthesis as you would give arguments to the method call.
If you first get the array (by calling the method without arguments), then index the array, the problem is void:
Dim item = temp.Position()(1)

Array properties are not very common, more often one expose either a indexed item property or a readonly property to a collection.
By using auto-declare property you are also breaking the recommendation of not returning the internal array instance.
 
As noted above, you could do something like:

Public Property Position As List(Of Byte)


And gain better functionality over the content.
 
Back
Top