• Saves Valuable Time
  • Trusted Accuracy for 12 Years
  • 15-Day Money-Back Guarantee

VB Equivalent to C# Generics

List

C# VB.NET
List<int> myVar = new List<int>(); Dim myVar As New List(Of Integer)

Dictionary

C# VB.NET
Dictionary<string, int> myVar = new Dictionary<string, int>(); Dim myVar As New Dictionary(Of String, Integer)

Defining a Generic Class

C# VB.NET
public class GenericClass<T> Public Class GenericClass (Of T)

Defining a Generic Class with a Constraint

C# VB.NET
public class GenericClass<T> where T: SomeBase Public Class GenericClass (Of T As SomeBase)

Defining a Generic Class with a 'new' Constraint

C# VB.NET
public class GenericClass<T> where T: new() Public Class GenericClass (Of T As New)

Defining a Generic Method

C# VB.NET
public int Compare<T>(T param1, T param2) Public Function Compare(Of T)(param1 As T, param2 As T) As Integer

Defining a Generic Method with a Constraint

C# VB.NET
void Swap<T>(ref T l, ref T r) where T: class Sub Swap(Of T As Class)(ByRef l As T, ByRef r As T)


Use Instant VB to convert from C# to VB.NET.     

Additional resource: VB.NET and C# Equivalents


Copyright © 1997 – 2017 Tangible Software Solutions Inc.