I have talked about array. Now let's talk about arraylist.
We need to write a lot of things in array before we can get it done by array. Now, arraylist supports add, insert, remove, sort, and binarysearch.
Previously, the code of Array (http://blog.csdn.net/xiong1000/archive/2006/07/13/914762.aspx) became simple.
Now the code for using arraylist is changed
Using system;
Using system. collections;
Public partial class_default: system. Web. UI. Page
{
Proteced void page_loade (Object sender, eventargs E)
{
Person Jimmy = new person ("Jimmy", "Zeng ");
Person stone = new person ("Stone", "Wang ");
Person Helen = new person ("Helen", "Liu ");
Arraylist people = new arraylist ();
People. Add (Jimmy );
People. Add (Stone );
People. Add (Helen );
Response. Write ("using the foreach. unsorting <br/> ");
Foreach (person P in People)
{
Response. Write (P. fullname + "<br/> ");
}
People. Sort ();
Response. Write ("using the foreach. Sorted <br/> ");
Foreach (person P in People)
{
Response. Write (P. fullname + "<br/> ");
}
Person jimmy2 = new person ("Jimmy", "Zeng ");
Int indexofjimmy2 = people. indexof (jimmy2 );
Response. Write ("jimmy2 is at" + indexofjimmy2 + "<br/> ");
Int indexofsamejimmy = people. binarysearch (jimmy2 );
Response. Write ("the equivalent Jimmy is at" + indexofsamejimmy + "<br/> ");
}
}