I want to write a class that was two different constructors. One version of the constructor takes a string parameter, the other thakes an array of strings. My plan was to have the first version *create* an array of strings of size one (containing the one string that was passed in), then call the other constructor with it.
However, two things stand in my way:
- I can't create the array on the fly, so I can't make the constructor call in one line.
- The compiler only allows a constructor call from another constructor when it is done on the first line of the function, so I can't create the array beforehand.
So, what am I left to do? Is my only option to fully write out what I want each constructor to do? I suppose I could have them both call a utility function to do what has to be done... but this is kinda annoying. I guess my problem is that I don't see why this can't be done... seems like a basic thing.
Here's an example of what I'm trying to do (just doing this shorthand, might have syntax errors)...
Constructor that takes array:
Code:
Public Sub New(ByVal myStrings() as String)
'Do stuff
End Sub
First option, create string array before hand:
Code:
Public Sub New(ByVal myString as String)
Dim temp() as String = { myString }
Me.New(temp)
End Sub
Won't compile! Constructor call only allowed on the first line... why the hell does it care if someting is done before hand?
And the second option is to somehow make that array and do the call in one line to get around the issues.
Well, more of rant than anything else, I guess. Any thoughts?