Results 1 to 3 of 3

Thread: Intellisense entering type rather than value

  1. #1
    njsokalski is offline VB.NET Forum Fanatic
    .NET Framework
    .NET 3.5
    Join Date
    Mar 2011
    Posts
    102
    Reputation
    31

    Intellisense entering type rather than value

    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.
    Nathan Sokalski

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,188
    Reputation
    2368
    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.

  3. #3
    Herman is offline VB.NET Forum Miyagee
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2011
    Location
    Montreal, QC, CA
    Posts
    448
    Reputation
    346
    As noted above, you could do something like:

    Public Property Position As List(Of Byte)


    And gain better functionality over the content.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking