VB语法:返回函数的类型,返回通用列表的动态数组

时间:2014-07-01 19:56:08

标签: vb.net function syntax return-type

为了简洁和清晰起见,我想将几​​行VB代码转换为函数调用。目前,代码填充了通用列表的动态数组:

Dim itemCount as Integer = 5
Dim myarr(itemCount - 1) As List(Of DataRow)
' some code that populates myarr

对于将返回myarr的函数,返回类型的语法是什么?

1 个答案:

答案 0 :(得分:1)

以下是示例代码。类型为List(Of DataRow)(),也可以通过TypeName验证。

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim m() As List(Of DataRow)
    m = getTest()
End Sub

Private Function getTest() As List(Of DataRow)()
    Dim m(10) As List(Of DataRow)
    MessageBox.Show(TypeName(m))
    For i = 0 To 10
        m(i) = New List(Of DataRow)
    Next
    Return m
End Function