ArrayList Demo: hold class : 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.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Collections Data Structure » ArrayListScreenshots 
ArrayList Demo: hold class
ArrayList Demo: hold class
  
/*
Learning C# 
by Jesse Liberty

Publisher: O'Reilly 
ISBN: 0596003765
*/
 using System;
 using System.Collections;

 namespace ArrayListDemo
 {
     // a class to hold in the array list
     class Employee
     {
         private int empID;
         public Employee(int empID)
         {
             this.empID = empID;
         }
         public override  string ToString()
         {
             return empID.ToString();
         }
         public int EmpID
         {
             get return empID; }
             set empID = value; }
         }
     }

     public class ArrayListDemoTester
     {
         public void Run()
         {
             ArrayList empArray = new ArrayList();
             ArrayList intArray = new ArrayList();

             // populate the arraylists
             for (int i = 0;i<5;i++)
             {
                 empArray.Add(new Employee(i+100));
                 intArray.Add(i*5);
             }

             // print each member of the array
             foreach (int i in intArray)
             {
                 Console.Write("{0} ", i.ToString());
             }

             Console.WriteLine("\n");

             // print each employee
             foreach(Employee e in empArray)
             {
                 Console.Write("{0} ", e.ToString());
             }

             Console.WriteLine("\n");
             Console.WriteLine("empArray.Capacity: {0}",
                 empArray.Capacity);
         }

         [STAThread]
         static void Main()
         {
             ArrayListDemoTester t = new ArrayListDemoTester();
             t.Run();
         }
     }
 }

           
         
    
  
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.illustrates the use of ArrayList properties and methodsillustrates the use of ArrayList properties and methods
12.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
13.illustrates the use of ArrayLists 2illustrates the use of ArrayLists 2
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.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.