Can I pass an argument to a function that is EITHER
a List or ArrayList?
I have a function that reads csv files, and some files have only one column. For files that have more than one column, I need to put that data into a List where each element is a List of type String. If there is only one column, then the data type would be just a simple List of type String. I want to pass by reference, but it's not a necessity. Here's an example of how the declaration looks now.
Private Sub readTextFile(ByVal file As String, ByRef al_txtFileContents As ArrayList)
I would like the ArrayList to be switched to a List, but I can't pass a generic List (as far as I know), because I always need the Of Type modifier, and there are two variations on the theme. Additionally, I'd like to be able to handle ArrayLists as well. All of these are collections, right? Is there a way to treat a parameter as a generic list?
I found a reference that showed how I could do the following, which compiles fine but won't run.
Call readTextFile(Of ArrayList)(file, al_OptionStrikeCodes)
Call readTextFile(Of List(Of List(Of String)))(file, al_OptionStrikeCodes)
to call a function with this declaration:
Private Sub readTextFile(Of T)(ByVal file As String, ByRef inputList As ICollection(Of T))
which keeps giving an invalid cast on the function call, even though the variable is declared as the same type as shown in the function call.
Is there an elegant way to do this?
P.S. I'm stuck using .Net 2