驚愕の事実
以下、先日言及したコレクションの変換に関して、いろいろと試している中で初めて知ったこと。
static void Main(string[] args) { object foo = new string[0]; System.Console.WriteLine("foo type : " + foo.GetType()); System.Console.WriteLine("foo is Array : " + (foo is Array)); System.Console.WriteLine("foo is IList : " + (foo is IList)); System.Console.WriteLine("foo is IList: " + (foo is IList )); System.Console.WriteLine("foo is List : " + (foo is List )); }
この実行結果は、以下のようになる。
foo type : System.String[] foo is Array : True foo is IList : True foo is IList: True foo is List : False
(foo is IList)が真なのは当たり前なのだが、まさか(foo is IList
正直なところ、一から勉強しなおそうと思った。
ちなみに、ジェネリックの型パラメタを
foo type : System.String[] foo is Array : True foo is IList : True foo is IList
うおー。完全に自信喪失。