is 的例子如下
1 2 3 4 5 6 7 8 9 10 11 12 13 | class Demo { static void Main() { string a = "1" ; System.Console.WriteLine(a is string ); } } /* 《程式語言教學誌》的範例程式 檔名:typetest1.cs 功能:示範 C# 程式 作者:張凱慶 時間:西元 2013 年 6 月 */ |
編譯執行,結果如下

as 的例子如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | class Demo1 {} class Demo2 {} class Demo3 { static void Main() { object [] DemoArray = new object [6]; DemoArray[0] = new Demo1(); DemoArray[1] = new Demo2(); DemoArray[2] = "hello" ; DemoArray[3] = 102; DemoArray[4] = 0.1; DemoArray[5] = null ; for ( int i = 0; i < DemoArray.Length; ++i) { string s = DemoArray[i] as string ; System.Console.Write( "{0}:" , i); if (s != null ) { System.Console.WriteLine( "'" + s + "'" ); } else { System.Console.WriteLine( "not a string" ); } } } } /* 《程式語言教學誌》的範例程式 檔名:typetest2.cs 功能:示範 C# 程式 作者:張凱慶 時間:西元 2013 年 6 月 */ |
編譯執行,結果如下

中英文術語對照 | |
---|---|
型態測試運算子 | type testing operator |
關鍵字 | keyword |
您可以繼續參考
運算式
型態轉換
相關目錄
回 C# 快速導覽
回 C# 教材
回首頁
參考資料
Standard ECMA-334 C# Language Specification
msdn: C# 運算子
沒有留言:
張貼留言