IList(Of String) parameter

jdy0803

Well-known member
Joined
Sep 9, 2012
Messages
73
Location
Santa Clarita
Programming Experience
10+
There is a function of which parameter is IList(Of String) type like following.

Public Function CopyFiles(ByVal files As IList(Of String)) As Boolean

I can call this function with static parameter like following

CopyFiles(New String() {"c:\1.avi", "C:\2.avi", "C:\3.avi"})

Then, how to make variable parameter with which replace {"c:\1.avi", "C:\2.avi", "C:\3.avi"}?
I did like this but error occurs.

Dim srcfilelist As IList(Of String) = New List(Of String)

srcfilelist.clear()
srcfilelist.add("c:\1.avi")
srcfilelist.add("c:\2.avi")
srcfilelist.add("c:\3.avi")
CopyFiles(New String() srcfilelist)
 
You can pass the srcfilelist object as argument to CopyFiles method, because that is a List(Of T) object, which implements the IList(Of T) interface.
You don't have to declare the srcfilelist as interface type, just use the List(Of String) type. Since it implements the interface it already satisfies the parameter type condition.
New String() {...} is a short way to create a String array and initialize it with some String elements, that is not relevant for your srcfilelist object.
 
Back
Top