System.ComponentModel.ComponentCollection Class

Assembly: System.dll
Namespace: System.ComponentModel
Summary
Specifies a collection of Component objects in the Container.
C# Syntax:
public class ComponentCollection : ReadOnlyCollectionBase
See also:
System.ComponentModel Namespace

System.ComponentModel.ComponentCollection Member List:

Public Constructors
ctor #1 Initializes a new instance of the ComponentCollection class with an array of components.
Public Properties
Count
(inherited from System.Collections.ReadOnlyCollectionBase)
Read-only

See base class member description: System.Collections.ReadOnlyCollectionBase.Count


Gets the number of elements contained in the ReadOnlyCollectionBase instance.
Item Read-only

Overloaded:
Item[string name] {get

Gets a specific Component in the Container.
Item Read-only

Overloaded:
Item[int index] {get

Gets a specific Component in the Container.
Public Methods
CopyTo Copies the entire collection to an array, starting at the specified index.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetEnumerator
(inherited from System.Collections.ReadOnlyCollectionBase)
See base class member description: System.Collections.ReadOnlyCollectionBase.GetEnumerator


Returns an enumerator that can iterate through the ReadOnlyCollectionBase instance.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Properties
InnerList
(inherited from System.Collections.ReadOnlyCollectionBase)
Read-only

See base class member description: System.Collections.ReadOnlyCollectionBase.InnerList


Gets the list of elements contained in the ReadOnlyCollectionBase instance.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.ComponentModel.ComponentCollection Member Details

ctor #1
Summary
Initializes a new instance of the ComponentCollection class with an array of components.
C# Syntax:
public ComponentCollection(
   IComponent[] components
);
Parameters:

components

An array of IComponent objects to initialize the collection with.

Return to top


Property: Count (read-only)
Inherited
See base class member description: System.Collections.ReadOnlyCollectionBase.Count

Summary
Gets the number of elements contained in the ReadOnlyCollectionBase instance.
C# Syntax:
public int Count {get;}
Implements:
ICollection.Count

Return to top


Property: InnerList (read-only)
Inherited
See base class member description: System.Collections.ReadOnlyCollectionBase.InnerList

Summary
Gets the list of elements contained in the ReadOnlyCollectionBase instance.
C# Syntax:
protected ArrayList InnerList {get;}

Return to top


Overloaded Property: Item (read-only)
Summary
Gets a specific Component in the Container.
C# Syntax:
public virtual IComponent this[string name] {get;}
Parameters:

name

The name of the Component to get.

Remarks
This method can be overridden by a derived class.

Note ComponentCollection.Item works only when the component is sited, which typically occurs only at design time. To site a Component at run time, set the Component.Site property of the Component. Then, ComponentCollection.Item can get the Component whose Component.Site property ISite.Name is the name parameter.
See also:
ISite.Name | Component.Site

Return to top


Overloaded Property: Item (read-only)
Summary
Gets a specific Component in the Container.
C# Syntax:
public virtual IComponent this[int index] {get;}
Parameters:

index

The index of the Component to get.

Remarks
This method can be overridden by a derived class.

Return to top


Method: CopyTo(
   IComponent[] array,
   int index
)
Summary
Copies the entire collection to an array, starting at the specified index.
C# Syntax:
public void CopyTo(
   IComponent[] array,
   int index
);
Parameters:

array

An array of IComponent objects to copy elements of the collection to.

index

The index of the array parameter at which copying begins.

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~ComponentCollection();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetEnumerator()
Inherited
See base class member description: System.Collections.ReadOnlyCollectionBase.GetEnumerator

Summary
Returns an enumerator that can iterate through the ReadOnlyCollectionBase instance.
C# Syntax:
public IEnumerator GetEnumerator();
Return Value:
An IEnumerator for the ReadOnlyCollectionBase instance.
Implements:
IEnumerable.GetEnumerator
Remarks
Enumerators only allow reading the data in the collection. Enumerators cannot be used to modify the underlying collection.

Initially, the enumerator is positioned before the first element in the collection. IEnumerator.Reset also brings the enumerator back to this position. At this position, calling IEnumerator.Current throws an exception. Therefore, you must call IEnumerator.MoveNext to advance the enumerator to the first element of the collection before reading the value of IEnumerator.Current.

IEnumerator.Current returns the same object until either IEnumerator.MoveNext or IEnumerator.Reset is called. IEnumerator.MoveNext sets IEnumerator.Current to the next element.

After the end of the collection is passed, the enumerator is positioned after the last element in the collection, and calling IEnumerator.MoveNext returns false. If the last call to IEnumerator.MoveNext returned false, calling IEnumerator.Current throws an exception. To set IEnumerator.Current to the first element of the collection again, you can call IEnumerator.Reset followed by IEnumerator.MoveNext.

An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying or deleting elements, the enumerator is irrecoverably invalidated and the next call to IEnumerator.MoveNext or IEnumerator.Reset throws an InvalidOperationException. If the collection is modified between IEnumerator.MoveNext and IEnumerator.Current, IEnumerator.Current will return the element that it is set to, even if the enumerator is already invalidated.

The enumerator does not have exclusive access to the collection; therefore, enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads could still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.

See also:
IEnumerator

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.