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

C# Equivalent to VB Generics

List

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

Dictionary

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

Defining a Generic Class

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

Defining a Generic Class with a Constraint

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

Defining a Generic Class with a 'new' Constraint

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

Defining a Generic Method

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

Defining a Generic Method with a Constraint

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


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

Additional resource: VB.NET and C# Equivalents


Copyright © 1997 – 2017 Tangible Software Solutions Inc.