開発環境
- Microsoft Windows 7 Home Premium (OS)
- Microsoft Visual C# 2010 Express Edition (IDE)
- 言語: C#
独習C# 第3版 ハーバート・シルト (著) エディフィストラーニング株式会社 矢嶋聡 (監修, 翻訳) の第14章(プリプロセッサ、実行時の型の識別、null許容型、高度なトピック)の理解度チェック1、2、3を解いてみる。
1.
条件付きコンパイルを行うために使用するプリプロセッサディレクティブ一覧。
- #if
- #elif
- #else
- #endif
2.
#elifの意味はelse if。
3.
実行時にオブジェクトの型情報を表すSystem.Typeインスタンスを取得するにはtypeof()演算子を使えばいい。
コード
using System; using System.Collections.Generic; public class BaseClass { } public class DerivedClass : BaseClass { } class Tester { public void Run() { Type a = typeof(Math); Type b = typeof(List<>); Type c = typeof(int); Console.WriteLine("{0}\n{1}\n{2}", a.FullName, b.FullName, c.FullName); } static void Main() { Tester t = new Tester(); t.Run(); } }
入出力結果(Console Window)
System.Math System.Collections.Generic.List`1 System.Int32 続行するには何かキーを押してください . . .
0 コメント:
コメントを投稿