/*6*/ PrintEntries("al1", al1); /*7*/ PrintEntries("al2", al2); } void PrintEntries(String^ s, ArrayList^ aList) { Console::Write("{0}: ", s); for each(Object^ o in aList) { Console::Write("/t{0}", o); } Console::WriteLine(); } 插1:程序輸出
al1: Red Blue Green Yellow al2: Red Blue Green Yellow al1: Brown Green Yellow Black al2: Red Blue Green Yellow ArrayList al1由4個代表不同顏色的字符串組成,通過在標記3中調用ArrayList::Clone函數,可以對此對象作一個完整的復制,所以,標記2與4表示的輸出完全相同。