find item in arraylist using indexof method
IndexOf method is used to determine if a particular item exists in an ArrayList. If an item exists, the index of that item is returned and if the item does not exist, -1 is returned.
The above statement returns zero because "Customer1" is the first item in the ArrayList.
private void Form1_Load(object sender, EventArgs e) { ArrayList arrayList = new ArrayList(); arrayList.Add("Customer1"); arrayList.Add("Customer2"); arrayList.Add("Customer3"); arrayList.Add("Customer4"); arrayList.Add("Customer5"); MessageBox.Show(arrayList.IndexOf("Customer1").ToString()); }
The above statement returns zero because "Customer1" is the first item in the ArrayList.
ArrayList Articles
- retrieve arraylist items using enumerators
- retrieve arraylist items using for each loop
- retrieve arraylist items using indexers
- insert items to the arraylist using insert and insertrange method
- remove items from arraylist
- bind arraylist with gridview control in asp net application
- how to bind arraylist with dropdownlist in asp net application
- how to bind arraylist with radiobuttonlist in asp.net application
- convert arraylist to string array