why in VB.Net I

Could anyone let me know why in VB.Net Im getting this error on the third line of code below?


ERROR:

Option Strict On disallows implicit conversions from 'System.Object' to 'VBNET.HowTo.Address'.

CODE:
ReadOnly Property CurrentAddress() As Address
Get
Return AddressBook.Items(CurrentAddressIndex - 1)
End Get
End Property

I declare like this:
Public AddressBook As AddressBook
Private _currentAddressIndex As Integer

Thanks

Comments

  • either turn off Option Strict (not recommended), or use the "As" operator to cast to correct object type. In your case:

    [code]
    ReadOnly Property CurrentAddress() As Address
    Get
    Return AddressBook.Items(CurrentAddressIndex - 1) As Address
    End Get
    End Property
    [/code]

    : Could anyone let me know why in VB.Net Im getting this error on the third line of code below?
    :
    :
    : ERROR:
    :
    : Option Strict On disallows implicit conversions from 'System.Object' to 'VBNET.HowTo.Address'.
    :
    : CODE:
    : ReadOnly Property CurrentAddress() As Address
    : Get
    : Return AddressBook.Items(CurrentAddressIndex - 1)
    : End Get
    : End Property
    :
    : I declare like this:
    : Public AddressBook As AddressBook
    : Private _currentAddressIndex As Integer
    :
    : Thanks
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion