c#中可以用is來判斷物件的真實型態
並且不論是其本身的class或繼承的基底,甚至是有實現的界面都會回傳true
ex:
Interface I1{}
class C1:I1{}
class C2:C1 {}
C1 c1 = new C1();
C2 c2 = new C2();
C1 c21 = new C2();
c1 is C1; // true
c1 is C2; // false
c2 is C1; // true
c2 is C2; // true
c21 is C1; // true
c21 is C2; // true
c1 is I1; // true
c2 is I1; // true
沒有留言:
張貼留言