Passing a constant array to a function in VB.NET

前端 未结 4 544
悲哀的现实
悲哀的现实 2021-01-18 11:30

I know that you can easily pass an array to a function, like the code below shows

Private Sub SomeFunction(ByVal PassedArray() As String)
    For i As Intege         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-18 12:01

    Another thing I just thought of that doesn't directly answer the question, but perhaps gets at the poster's intent - the ParamArray keyword. If you control the function you are calling into, this can make life a whole lot easier.

    Public Function MyFunction(ByVal ParamArray p as String())
       ' p is a normal array in here
    End Function
    
    ' This is a valid call
    MyFunction(New String() {"a", "b", "c", "d"})
    
    ' So is this
    MyFunction("a", "b", "c", "d")
    

提交回复
热议问题