Use the IndexOf() and LastIndexOf() methods to display the first and last occurrence : ArrayList « Data Structure « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / CSharp Tutorial » Data Structure » ArrayList 




using System;
using System.Collections;

class MainClass
{
  public static void Main()
  {
    ArrayList myArrayList = new ArrayList();
    myArrayList.Add("A");
    myArrayList.Add("A");
    myArrayList.Add("A");
    myArrayList.Add("A");
    myArrayList.Add("A");
    myArrayList.Add("A");
    myArrayList.Add("A");
    myArrayList.Add("A");
    myArrayList.Add("A");
    myArrayList.Add("A");
    

    string[] anotherStringArray = {"Here's""some""more""text"};
    myArrayList.SetRange(0, anotherStringArray);


    if (myArrayList.Contains("text"))
    {
      int index = myArrayList.IndexOf("text");
      Console.WriteLine("myArrayList does contain the word 'text'");
      Console.WriteLine("'text' first occurs at index " + index);
      index = myArrayList.LastIndexOf("text");
      Console.WriteLine("'text' last occurs at index " + index);
    }

  }
}














11.21.ArrayList
11.21.1.Demonstrates the 3 constructors of ArrayList
11.21.2.Get the number of elements
11.21.3.Remove elements from ArrayList
11.21.4.Capacity and element count
11.21.5.Change contents using array indexing
11.21.6.Sort and search an ArrayList
11.21.7.Use enumerator to access list
11.21.8.Re-enumerate the list
11.21.9.Make an ArrayList Synchronized
11.21.10.Insert and remove at specific index
11.21.11.Clear an ArrayList
11.21.12.Create a string array and use the ICollection.CopyTo method to copy the contents of the ArrayList
11.21.13.Use ArrayList.ToArray to create an object array from the contents of the collection
11.21.14.Box ints into ArrayList
11.21.15.ArrayList: AddRange
11.21.16.Insert item to ArrayList by index
11.21.17.Use ArrayList copy constructor
11.21.18.IsFixedSize and IsReadOnly properties
11.21.19.Insert(), AddRange(), and InsertRange() methods
11.21.20.Use the SetRange() method to copy the elements from anotherStringArray to myArrayList, starting at index 0
11.21.21.Use the Contains() method to determine if the string 'text' is in the ArrayList
11.21.22.Use the IndexOf() and LastIndexOf() methods to display the first and last occurrence
11.21.23.Remove element 0, first 'text' element, and two elements starting at index 3
11.21.24.Use the Reverse() method to reverse myArrayList
11.21.25.Using the TrimToSize() method to reduce the capacity of ArrayList
11.21.26.Using the GetRange() method to get two elements from myArrayList, starting at index 1
11.21.27.Get an enumerator using the GetEnumerator() method and use it to read the elements in ArrayList
11.21.28.Use the Reset() method and access the first row again using MoveNext()
11.21.29.Sort arraylist using custom IComparer
11.21.30.Sort ArrayList using the default comparer and a custom comparer that reverses the sort order.
11.21.31.Filter int from ArrayList
11.21.32.extends ArrayList to create NameCollection
11.21.33.ArrayList Query
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.