illustrates the use of ArrayLists 2 : ArrayList « Collections Data Structure « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » Collections Data Structure » ArrayList 




illustrates the use of ArrayLists 2
illustrates the use of ArrayLists 2
  
/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy

Publisher: Sybex;
ISBN: 0782129110
*/

/*
  Example11_1.cs illustrates the use of ArrayLists
*/

using System;
using System.Collections;

public class Example11_1
{

  // the DisplayArrayList() method displays the elements in the
  // ArrayList that is supplied as a parameter
  public static void DisplayArrayList(
    string arrayListName, ArrayList myArrayList
  )
  {
    for (int counter = 0; counter < myArrayList.Count; counter++)
    {
      Console.WriteLine(arrayListName + "[" + counter + "] = " +
        myArrayList[counter]);
    }
  }

  public static void Main()
  {

    // create an ArrayList object
    ArrayList myArrayList = new ArrayList();

    // display the Capacity property
    Console.WriteLine("myArrayList.Capacity = " +
      myArrayList.Capacity);

    // add four strings to myArrayList using the Add() method
    myArrayList.Add("This");
    myArrayList.Add("is");
    myArrayList.Add("a");
    myArrayList.Add("test");

    // display the contents of myArrayList using DisplayArrayList()
    DisplayArrayList("myArrayList", myArrayList);

    // create another ArrayList, passing myArrayList to the
    // constructor of the new ArrayList
    ArrayList anotherArrayList = new ArrayList(myArrayList);

    // display the contents of anotherArrayList
    DisplayArrayList("anotherArrayList", anotherArrayList);

  }

}

           
         
    
  














Related examples in the same category
1.Add items to ArrayList and use foreach loop to check
2.Add array to ArrayList
3.Remove range from ArrayList
4.Clone an ArrayList
5.CopyTo, ToArray(), ToArray(typeof(String))
6.Using foreach to loop through ArrayList and use Indexer of ArrayList
7.Check InvalidCastException when using foreach loop with ArrayList
8.Binary Search an ArrayList
9.Inserting into an ArrayList by index
10.Checks time needed for list operations using an ArrayList implementationChecks time needed for list operations using an ArrayList implementation
11.ArrayList Demo: hold classArrayList Demo: hold class
12.illustrates the use of ArrayList properties and methodsillustrates the use of ArrayList properties and methods
13.illustrates the use of an ArrayList that contains objects of the Car classillustrates the use of an ArrayList that contains objects of the Car class
14.Convert an ArrayList into an arrayConvert an ArrayList into an array
15.Sort and search an ArrayListSort and search an ArrayList
16.Demonstrate ArrayListDemonstrate ArrayList
17.Search for the first occurrence of the duplicated value
18.Search for the first occurrence of the duplicated value in the last section of the ArrayList
19.Search for the first occurrence of the duplicated value in a section of the ArrayList
20.Search for the first occurrence of the duplicated value in a small section at the end of the ArrayList
21.Convert a ArrayList object to a array
22.Represents a loose abstraction of an arraylist, wheres the buffer array is available for public access.
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.