I\'m normally at home in C#, and I\'m looking at a performance issue in some VB.NET code -- I want to be able to compare something to the default value for a type (kind of l
This is not a complete solution, as your original C# code doesn't compile. You can use Nothing via a local variable:
Public Class GenericThing(Of T)
Public Sub Foo(id As T)
Dim defaultValue As T = Nothing
If id <> defaultValue Then
Console.WriteLine("Not default")
Else
Console.WriteLine("Default")
End If
End Function
End Class
That doesn't compile, in the same way that the C# version doesn't compile - you can't compare values of unconstrained type parameters like that.
You can use EqualityComparer(Of T) though - and then you don't even need the local variable:
If Not EqualityComparer(Of T).Default.Equals(id, Nothing) Then