System.Collections Namespace
Implements the IList interface using an array whose size is dynamically increased as required.
Visibility |
Name |
Parameters |
Return Type |
public static |
Adapter |
(
IList
list
)
|
ArrayList
|
public |
Add |
(
Object
value
)
|
Int32
|
public |
AddRange |
(
ICollection
c
)
|
Void
|
public |
BinarySearch |
(
Object
value
,
IComparer
comparer
)
|
Int32
|
public |
BinarySearch |
(
Object
value
)
|
Int32
|
public |
BinarySearch |
(
Int32
index
,
Int32
count
,
Object
value
,
IComparer
comparer
)
|
Int32
|
public |
Clear |
( )
|
Void
|
public |
Clone |
( )
|
Object
|
public |
Contains |
(
Object
item
)
|
Boolean
|
public |
CopyTo |
(
Int32
index
,
Array
array
,
Int32
arrayIndex
,
Int32
count
)
|
Void
|
public |
CopyTo |
(
Array
array
,
Int32
arrayIndex
)
|
Void
|
public |
CopyTo |
(
Array
array
)
|
Void
|
public static |
FixedSize |
(
ArrayList
list
)
|
ArrayList
|
public static |
FixedSize |
(
IList
list
)
|
IList
|
public |
GetEnumerator |
(
Int32
index
,
Int32
count
)
|
IEnumerator
|
public |
GetEnumerator |
( )
|
IEnumerator
|
public |
GetRange |
(
Int32
index
,
Int32
count
)
|
ArrayList
|
public |
IndexOf |
(
Object
value
,
Int32
startIndex
)
|
Int32
|
public |
IndexOf |
(
Object
value
,
Int32
startIndex
,
Int32
count
)
|
Int32
|
public |
IndexOf |
(
Object
value
)
|
Int32
|
public |
Insert |
(
Int32
index
,
Object
value
)
|
Void
|
public |
InsertRange |
(
Int32
index
,
ICollection
c
)
|
Void
|
public |
LastIndexOf |
(
Object
value
)
|
Int32
|
public |
LastIndexOf |
(
Object
value
,
Int32
startIndex
,
Int32
count
)
|
Int32
|
public |
LastIndexOf |
(
Object
value
,
Int32
startIndex
)
|
Int32
|
public static |
ReadOnly |
(
ArrayList
list
)
|
ArrayList
|
public static |
ReadOnly |
(
IList
list
)
|
IList
|
public |
Remove |
(
Object
obj
)
|
Void
|
public |
RemoveAt |
(
Int32
index
)
|
Void
|
public |
RemoveRange |
(
Int32
index
,
Int32
count
)
|
Void
|
public static |
Repeat |
(
Object
value
,
Int32
count
)
|
ArrayList
|
public |
Reverse |
(
Int32
index
,
Int32
count
)
|
Void
|
public |
Reverse |
( )
|
Void
|
public |
SetRange |
(
Int32
index
,
ICollection
c
)
|
Void
|
public |
Sort |
(
Int32
index
,
Int32
count
,
IComparer
comparer
)
|
Void
|
public |
Sort |
(
IComparer
comparer
)
|
Void
|
public |
Sort |
( )
|
Void
|
public static |
Synchronized |
(
ArrayList
list
)
|
ArrayList
|
public static |
Synchronized |
(
IList
list
)
|
IList
|
public |
ToArray |
(
Type
type
)
|
Array
|
public |
ToArray |
( )
|
Object
|
public |
TrimToSize |
( )
|
Void
|
|
The capacity of an ArrayList is the number of elements the list can hold. As elements are added to an ArrayList, the capacity is automatically increased as required through reallocation. The capacity can be decreased by calling TrimToSize or by setting the Capacity property explicitly.
Indexes in this collection are zero-based.
The following example shows how to create and initialize an ArrayList and how to print out its values.
using System;
using System.Collections;
public class SamplesArrayList {
public static void Main() {
// Creates and initializes a new ArrayList.
ArrayList myArrayList = new ArrayList();
myArrayList.Add ("Hello");
myArrayList.Add ("World");
myArrayList.Add ("!");
// Displays the properties and values of the ArrayList.
Response.Write ("myArrayList" + "<br>");
Response.Write ("Count: " + myArrayList.Count + "<br>");
Response.Write ("Capacity: " + myArrayList.Capacity + "<br>");
Response.Write ("Values:" + "<br>");
PrintValues ( myArrayList );
}
public static void PrintValues ( IEnumerable myList ) {
System.Collections.IEnumerator myEnumerator = myList.GetEnumerator();
while ( myEnumerator.MoveNext() ) {
Response.Write (myEnumerator.Current + "<br>");
}
Response.Write ("<br>");
}
}
Imports System
Imports System.Collections
Public Class SamplesArrayList
Public Shared Sub Main()
' Creates and initializes a new ArrayList.
Dim myArrayList As New ArrayList()
myArrayList.Add ("Hello")
myArrayList.Add ("World")
myArrayList.Add ("!")
' Displays the properties and values of the ArrayList.
Response.Write ("myArrayList" & "<br>")
Response.Write ("Count: " & myArrayList.Count & "<br>")
Response.Write ("Capacity: " & myArrayList.Capacity & "<br>")
Response.Write ("Values:" & "<br>")
PrintValues (myArrayList)
End Sub
Public Shared Sub PrintValues (myList As IEnumerable)
Dim myEnumerator As System.Collections.IEnumerator = _
myList.GetEnumerator()
While myEnumerator.MoveNext()
Response.Write (myEnumerator.Current & "<br>")
End While
Response.Write ("<br>")
End Sub
End Class |
|
C# |
VB |
|
|