![]() |
[VB.Net] Overloading a class' Constructor
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:
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) Code:
Public Sub New(ByVal myString as String) 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? |
Here is the answer you are lookin for :)
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load |
For some reason, I've never known that you could do: Me.mysub(New String() {myString}) I've tried and tried to create arrays on the fly, and I guess I've never typed it like that. I think I might have been putting an equals sign in there, as in Me.mysub(New String() = {myString})
*sigh*.... why oh why can't my job just let me do C#? thanks. |
Heh, yes, c# would be much better, thats all I use, but many more people know VB(.NET).
|
All times are GMT -8. The time now is 03:52 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project