tags:

views:

112

answers:

2

What is the VB Equivalent of the following C# boolean expression?

data.GetType() == typeof(System.Data.DataView)

Note: The variable data is declared as IEnumerable.

+8  A: 

As I recall

TypeOf data Is System.Data.DataView

Edit:
As James Curran pointed out, this works if data is a subtype of System.Data.DataView as well.

If you want to restrict that to System.Data.DataView only, this should work:

data.GetType() Is GetType(System.Data.DataView)
R. Bemrose
Note, however, if the VB "is" is anyhting like the C# "is", that would be true if data is a DataView or derived from DataView. The original code would only be true if data was specifically a DataView object.
James Curran
@James Curran: Good point, I've updated it with the other way I know of to check that (ironically, the way I originally had it before editing)
R. Bemrose
@James: VB’s `Is` is actually identical to `object.ReferenceEquals`. But `Typeof … Is` indeed equals C#’s `is` operator.
Konrad Rudolph
A: 

Try this.

GetType(Foo)