ElementCollection<T> Class
Represents a base generic class for Element collections.
public abstract class ElementCollection<T> : ElementCollection, IList, ICollection, IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable
Public MustInherit Class ElementCollection(Of T As Element)
Inherits ElementCollection
Implements IList, ICollection, IList(Of T), ICollection(Of T), IEnumerable(Of T), IEnumerable
Type Parameters
T
An Element derived type.
- Inheritance:
- System.ObjectElementCollection<T>
- Derived
Implements
Properties
Count
Gets the number of elements contained in the ElementCollection<T>.
Property Value
- System.Int32
The number of elements contained in the ElementCollection<T>.
Item[Int32]
Gets or sets the element at the specified index.
Parameters
index
- System.Int32
The zero-based index of the element to get or set.
Property Value
- T
The element at the specified index.
Methods
Add(T)
Adds an object to the end of the ElementCollection<T>.
Parameters
item
- T
The object to be added to the end of the ElementCollection<T>.
Cast<TElement>(Int32)
Gets the element at the specified index and casts it to the specified type.
public TElement Cast<TElement>(int index)
where TElement : T
Public Function Cast(Of TElement As T)(index As Integer) As TElement
Parameters
index
- System.Int32
The zero-based index of the element to get.
Returns
- TElement
The element at the specified index casted to TElement
type.
Type Parameters
TElement
The type to cast the element to.
Remarks
This method serves as a utility method for casting. Default C# explicit casting, when used in a chain, makes code hard to write and read. This method makes the chain casting code more clear and maintainable.
Exceptions
- System.ArgumentOutOfRangeException
index
is less than 0 or is equal to or greater than Count.
- System.InvalidCastException
An element at the specified index cannot be cast to type TElement
.
Clear()
Removes all elements from the ElementCollection<T>.
Contains(T)
Determines whether an element is in the ElementCollection<T>.
Parameters
item
- T
The element to locate in the ElementCollection<T>.
Returns
- System.Boolean
true
if item is found in the ElementCollection<T>; otherwise, false
.
CopyTo(T[], Int32)
Copies the entire ElementCollection<T> to a compatible one-dimensional array, starting at the specified index of the target array.
public void CopyTo(T[] array, int arrayIndex)
Public Sub CopyTo(array As T(), arrayIndex As Integer)
Parameters
array
- T[]
The one-dimensional array that is the destination of the elements copied from ElementCollection<T>.
arrayIndex
- System.Int32
The zero-based index in array at which copying begins.
GetEnumerator()
Returns an enumerator that iterates through the ElementCollection<T>.
Returns
- System.Collections.Generic.IEnumerator<T>
An enumerator for the ElementCollection<T>.
IndexOf(T)
Searches for the specified element and returns the zero-based index of the first occurrence within the entire ElementCollection<T>.
Parameters
item
- T
The element to locate in the ElementCollection<T>.
Returns
- System.Int32
The zero-based index of the first occurrence of item within the entire ElementCollection<T>, if found; otherwise, -1.
Insert(Int32, T)
Inserts an element into the ElementCollection<T> at the specified index.
Parameters
index
- System.Int32
The zero-based index at which item
should be inserted.
item
- T
The element to insert.
Remove(T)
Removes the first occurrence of a specific element from the ElementCollection<T>.
Parameters
item
- T
The element from the ElementCollection<T>.
Returns
- System.Boolean
true if item is successfully removed; otherwise, false. This method also returns false if item was not found in the ElementCollection<T>.
RemoveAt(Int32)
Removes the element at the specified index of the ElementCollection<T>.
Parameters
index
- System.Int32
The zero-based index of the element to remove.
Inherited Properties
Content | Gets the content of the current ElementCollection. (Inherited from ElementCollection) |
SupportedElementTypes | Gets a sequence of ElementTypes that can be contained in this collection. (Inherited from ElementCollection) |
Inherited Methods
CopyTo(Element[], System.Int32) | Copies the elements of the ElementCollection to an System.Array, starting at a particular System.Array index. (Inherited from ElementCollection) |
IndexOf(Element) | Determines the index of a specific Element in the ElementCollection. (Inherited from ElementCollection) |