What is the VB.NET equivalent of the C# "is" keyword?
Try the following
if TypeOf x Is IFoo Then
...
Like this:
If TypeOf x Is IFoo Then
The direct translation is:
If TypeOf x Is IFoo Then
...
End If
But (to answer your second question) if the original code was better written as
var y = x as IFoo;
if (y != null)
{
... something referencing y rather than (IFoo)x ...
}
Then, yes,
Dim y = TryCast(x, IFoo)
If y IsNot Nothing Then
... something referencing y rather than CType or DirectCast (x, IFoo)
End If
is better.