■No26109 (ま さん) から引用: > private void test2() > { > ArrayList list1 = new ArrayList(); > ArrayList list2 = new ArrayList(); > > list1.Add("OKOD"); > list1.Add("GOD"); > list1.Add("ODD"); > list1.Add("EVEN"); > list1.Add("POD"); > list1.Add("TODO"); > list1.Add("QUEEN"); > > string key = "OD"; > foreach (string s in list1) > { > if (s.IndexOf(key) > -1) list2.Add(s); > } > > Console.WriteLine("------ result2 ------"); > foreach (string s in list2) > { > Console.WriteLine("{0}", s); > } > > Console.In.ReadLine(); > > } > } これの ArrayList を単に StringCollection(これならVisualStudio2003にもある)に変えれば、 私が想定したものになります。 そうする理由:実行時にキャスト例外が発生する可能性があるのが嫌。ただそれだけ。
- Child Tree -