Can I pass an array of arguments in place of individual arguments? VB.Net

Viewed 42

For a generic example

If I have a class with a constructor like so

Public Class Person

Public Property A As String
Public Property B As String
Public Property C As String
`
`
`
Public Property Z As String

Public Sub New(AA As String, BB As String, CC As String...)
A=AA
B=BB
C=CC
`
`
`
Z=ZZ
End Sub

And I have an Array of Strings, that represent AA, BB, and CC, etc...

Can I use that array to pass the arguments in my New constructor?

Edit:

The TL;DR is write a new constructor that accepts a ParamArray provided they are all of the same type.

Like so:

I think I got it:

        Public Sub New(ParamArray strings As String())
            A= strings(0)
            B= strings(1)
            C= strings(2)
        End Sub

        Dim cArray() As String = {"dog", "cat", "bird"}

        Dim ABC As New Person(cArray)

0 Answers
Related