如何从数组中读取列值

时间:2018-10-23 17:37:21

标签: vb.net vb6-migration

我有下面的VB6代码,其中在VB6代码中有两个参数被传递以从集合数组中读取列值。如何将此代码迁移到Vb.Net。甚至在下面我也提到了向导生成的VB.Net代码。

Private m_colBookmarks As Collection
Private Const COL_ERR_BKMARK_COMP_TITLE = 2
Private Property Get BookmarkCompTitle(ByVal strBookmarkNum As String) As String          
    BookmarkCompTitle = m_colBookmarks(strBookmarkNum)(COL_ERR_BKMARK_COMP_TITLE)
End Property

这是vb.net代码。

 Private ReadOnly Property BookmarkCompTitle(ByVal strBookmarkNum As String) As String
    Get          

        BookmarkCompTitle = m_colBookmarks.Item(strBookmarkNum)(COL_ERR_BKMARK_COMP_TITLE)
    End Get
End Property

1 个答案:

答案 0 :(得分:1)

Option Strict On

Imports System.Collections.ObjectModel

Public Class Class1
    Private m_colBookmarks As Collection(Of String())
    Private Const COL_ERR_BKMARK_COMP_TITLE = 2

    ' here Is the vb.net code.
    Private ReadOnly Property BookmarkCompTitle(ByVal strBookmarkNum As String) As String
        Get
            Dim bookmarkNum As Integer

            If Not Int32.TryParse(strBookmarkNum, bookmarkNum) OrElse bookmarkNum < 0 Then                    
                Throw New ArgumentException("strBookmarkNum must be a positive integer.")
            End If

            BookmarkCompTitle = m_colBookmarks.Item(bookmarkNum)(COL_ERR_BKMARK_COMP_TITLE)
        End Get
    End Property
End Class