ちょっとフレームワーク的なメソッドで、不特定な型のジェネリックなリストの要素に対する操作をしたい場合。
ジェネリックなディクショナリも、System.Collections.IDictionaryにキャストできるっぽい。
private void SomeProcess(Object val) { if (val is System.Collections.IList) { System.Collections.IList undefList = (System.Collections.IList) val; foreach (Object obj in undefList) { // リストの中の要素に対する操作 } } }
ドキュメントの見方
List ジェネリック クラス (System.Collections.Generic)
System.Collections.Generic.Listは、System.Collections.IListにキャストできるってことだけど、どのドキュメントを見ればそれが判るんだ???
MSDNのドキュメントって、JavaDocの継承やインターフェースの関係ってどこを見ればいいんだ?
構文ってとこに書いてるのって、"IList"って名前空間書いてるけど、これで"System.Collections.IList"ってことなんか?
[SerializableAttribute] public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable