Generic Structure in Visual Basic .NET

Last Updated: March 19, 2020

You can create generic structures in VB.NET. This code is to create a List Structure

Public Structure List(Of type)
    Private items() As type
    Private index As Integer

    Public Sub New(ByVal size As Integer)
        ReDim items(size - 1)
        index = 0
    End Sub

    Public Sub Add(ByVal item As type)
        items(index) = item
        index += 1

    End Sub

End Structure

You can use following code to create instance from generic structure

Module Module1

    Sub Main()
        Dim myList As New List(Of Integer)(2)
    End Sub

End Module