Generics In Visual Basic .NET

To Explain the Generics in VB.NET I am going to create a class called List which you can add integer to the list

Inside the Sub Main() I will add two integers

How do you change the class to add String values
You create a new class then copy the code and change Integer to String
Like the code below

Although you have used the code reusability this is not good approach. SO VB.NET has Generics for this
I am using new keyword Of with type

When you create the instance form this class you have to use Of Integer as shown below

Now you can used this generic class for any data type which you find in the VB.NET

Leave a Reply

Your email address will not be published. Required fields are marked *