Im new to VB. I am coming from a Java background. In the following code
Sub PrintList(Of T)(ByVal list As List(Of T))
For Each obj As T In list
Console.Write(obj.ToString() + " ")
Next
Console.WriteLine()
End Sub
Can someone help me to understand what Sub PrintList(Of T)(ByVal list As List(Of T)) means?
Why do you need the (Of T) part? Why isn’t (ByVal list As List(Of T)) sufficient?
In Java, this would be something like:
The
(Of T)afterPrintListis the equivalent to the<T>beforevoidin the Java version. In other words, it’s declaring the type parameter for the generic method.