• Saves Valuable Time
  • Trusted Accuracy since 2004
  • 15-Day Money-Back Guarantee

C# Equivalent to VB Generics

Creating a List

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

Creating a 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)
End Class
public class GenericClass<T>
{
}

Defining a Generic Class with a Constraint

VB.NET C#
Public Class GenericClass (Of T As SomeBase)
End Class
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)
End Class
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
End Function
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)
End Sub
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 © 2004 – 2019 Tangible Software Solutions, Inc.