2010-07-02 22 views

cevap

52

Bunun gibi

if TypeOf x Is IFoo Then 
    ... 
+1

teşekkürler/TypeOf anahtar kelimesi eksik olduğum şeydir – Tahbaza

6

aşağıdaki deneyin:

If TypeOf x Is IFoo Then 
1

doğrudan çevirisidir:

If TypeOf x Is IFoo Then 
    ... 
End If 

Ama (ikinci soruyu cevaplamak için) orijinal kod daha iyi,

Sonra
var y = x as IFoo; 
if (y != null) 
{ 
    ... something referencing y rather than (IFoo)x ... 
} 

, evet olarak yazılmıştır eğer

Dim y = TryCast(x, IFoo) 
If y IsNot Nothing Then 
    ... something referencing y rather than CType or DirectCast (x, IFoo) 
End If 

daha iyi.