IEnumerable Interface
.NET Framework 1.1
Exposes the enumerator, which supports a simple iteration over a collection.
For a list of all members of this type, see IEnumerable Members.
IEnumerable must be implemented to support the ForEach semantics of Microsoft Visual Basic. COM classes that allow enumerators also implement this interface.
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
Assembly: Mscorlib (in Mscorlib.dll)
First it is an interface. The definition according to MSDN is
Exposes the enumerator, which supports a simple iteration over a non-generic collection.Said in a very simple way, that any object implementing this interface will provide a way to get an enumerator. An enumerator is used with the
foreach
as one example.
A List implements the IEnumerable interface.
// This is a collection that eventually we will use an Enumertor to loop through // rather than a typical index number if we used a for loop. List<string> dinosaurs = new List<string>(); dinosaurs.Add("Tyrannosaurus"); dinosaurs.Add("Amargasaurus"); dinosaurs.Add("Mamenchisaurus"); dinosaurs.Add("Deinonychus"); dinosaurs.Add("Compsognathus"); Console.WriteLine(); // HERE is where the Enumerator is gotten from the List<string> object foreach(string dinosaur in dinosaurs) { Console.WriteLine(dinosaur); } // You could do a for(int i = 0; i < dinosaurs.Count; i++) { string dinosaur = dinosaurs[i]; Console.WriteLine(dinosaur); }
Classes that Implement IEnumerable
Class | Description |
---|---|
Array | Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtime. |
ArrayList | Implements the IList interface using an array whose size is dynamically increased as required. |
AttributeCollection | Represents a collection of attributes. |
BaseChannelObjectWithProperties | Provides a base implementation of a channel object that wants to provide a dictionary interface to its properties. |
BaseCollection | Provides the base functionality for creating data-related collections in the System.Windows.Forms namespace. |
BindingContext | Manages the collection of BindingManagerBase objects for any object that inherits from the Control class. |
BitArray | Manages a compact array of bit values, which are represented as Booleans, where true indicates that the bit is on (1) and false indicates the bit is off (0). |
Cache | Implements the cache for a Web application. This class cannot be inherited. |
CaptureCollection | Represents a sequence of capture substrings. CaptureCollection returns the set of captures done by a single capturing group. |
CheckedListBox.CheckedIndexCollection | Encapsulates the collection of indexes of checked items (including items in an indeterminate state) in a CheckedListBox. |
CheckedListBox.CheckedItemCollection | Encapsulates the collection of checked items (including items in an indeterminate state) in a CheckedListBox control. |
ClerkMonitor | Contains a snapshot of all Clerks active in the process. |
CodeNamespaceImportCollection | Represents a collection of CodeNamespaceImport objects. |
CollectionBase | Provides the abstract (MustInherit in Visual Basic) base class for a strongly typed collection. |
ComboBox.ObjectCollection | Represents the collection of items in a ComboBox. |
Control.ControlCollection | Represents a collection of Control objects |
ControlCollection | Provides a collection container that enables ASP.NET server controls to maintain a list of their child controls. |
CookieCollection | Provides a collection container for instances of the Cookie class. |
CredentialCache | Provides storage for multiple credentials. |
DataBindingCollection | Provides a collection of DataBinding objects for an ASP.NET server control. This class cannot be inherited. |
DataColumnMappingCollection | Contains a collection of DataColumnMapping objects. |
DataGridColumnCollection | A collection of DataGridColumn derived column objects that represent the columns in a DataGrid control. This class cannot be inherited. |
DataGridItemCollection | Represents a collection of DataGridItem objects in a DataGrid control. |
DataKeyCollection | Represents a collection that contains the key field of each record in a data source. This class cannot be inherited. |
DataListItemCollection | Represents the collection of DataListItem objects in the DataList control. This class cannot be inherited. |
DataTableMappingCollection | A collection of DataTableMapping objects. This class cannot be inherited. |
DataView | Represents a databindable, customized view of a DataTable for sorting, filtering, searching, editing, and navigation. |
DataViewManager | Contains a default DataViewSettingCollection for each DataTable in a DataSet. |
DataViewSettingCollection | Contains a read-only collection of DataViewSetting objects for each DataTable in a DataSet. |
DesignerCollection | Represents a collection of designers. |
DictionaryBase | Provides the abstract (MustInherit in Visual Basic) base class for a strongly typed collection of key-and-value pairs. |
DirectoryEntries | Contains the children (child entries) of an entry in Active Directory. |
EventDescriptorCollection | Represents a collection of EventDescriptor objects. |
EventLogEntryCollection | Defines size and enumerators for a collection of EventLogEntry instances. |
Evidence | Defines the set of information that constitutes input to security policy decisions. This class cannot be inherited. |
GridItemCollection | Contains a collection of GridItem objects. |
GroupCollection | Represents a collection of captured groups. GroupCollection returns the set of captured groups in a single match. |
Hashtable | Represents a collection of key-and-value pairs that are organized based on the hash code of the key. |
HtmlTableCellCollection | A collection of HtmlTableCell objects that represent the cells in a single row of an HtmlTable control. This class cannot be inherited. |
HtmlTableRowCollection | A collection of HtmlTableRow objects that represent the rows of an HtmlTable control. This class cannot be inherited. |
HttpSessionState | Provides access to session-state values as well as session-level settings and lifetime management methods. |
HttpStaticObjectsCollection | Provides a static objects collection for the StaticObjects property. |
HybridDictionary | Implements IDictionary by using a ListDictionary while the collection is small, and then switching to a Hashtable when the collection gets large. |
ImageList.ImageCollection | Encapsulates the collection of Image objects in an ImageList. |
InternalDataCollectionBase | Provides the base functionality for creating collections. |
KeyInfo | Represents an XMLDSIG <KeyInfo> element. |
LinkLabel.LinkCollection | Represents the collection of links within a LinkLabel control. |
ListBox.ObjectCollection | Represents the collection of items in a ListBox. |
ListBox.SelectedIndexCollection | Represents the collection containing the indexes to the selected items in a ListBox. |
ListBox.SelectedObjectCollection | Represents the collection of selected items in the ListBox. |
ListDictionary | Implements IDictionary using a singly linked list. Recommended for collections that typically contain 10 items or less. |
ListItemCollection | A collection of ListItem objects in a list control. This class cannot be inherited. |
ListView.CheckedIndexCollection | Represents the collection containing the indexes to the checked items in a list view control. |
ListView.CheckedListViewItemCollection | Represents the collection of checked items in a list view control. |
ListView.ColumnHeaderCollection | Represents the collection of column headers in a ListView control. |
ListView.ListViewItemCollection | Represents the collection of items in a ListView control. |
ListView.SelectedIndexCollection | Represents the collection containing the indexes to the selected items in a list view control. |
ListView.SelectedListViewItemCollection | Represents the collection of selected items in a list view control. |
ListViewItem.ListViewSubItemCollection | Represents a collection of ListViewItem.ListViewSubItem objects stored in a ListViewItem. |
ManagementObjectCollection | Represents different collections of management objects retrieved through WMI. The objects in this collection are of ManagementBaseObject-derived types, including ManagementObject and ManagementClass.
The collection can be the result of a WMI query executed through a ManagementObjectSearcher object, or an enumeration of management objects of a specified type retrieved through a ManagementClass
representing that type. In addition, this can be a collection of
management objects related in a specified way to a specific management
object - in this case the collection would be retrieved through a method
such as GetRelated. The collection can be walked using the ManagementObjectCollection.ManagementObjectEnumerator and objects in it can be inspected or manipulated for various management tasks. |
MatchCollection | Represents the set of successful matches found by iteratively applying a regular expression pattern to the input string. |
Menu.MenuItemCollection | Represents a collection of MenuItem objects. |
MessageQueue | Provides access to a queue on a Message Queuing server. |
MethodDataCollection | Represents the set of methods available in the collection. |
NameObjectCollectionBase | Provides the abstract (MustInherit in Visual Basic) base class for a collection of associated String keys and Object values that can be accessed either with the key or with the index. |
NameObjectCollectionBase.KeysCollection | Represents a collection of the String keys of a collection. |
OdbcDataReader | Provides a way of reading a forward-only stream of data rows from a data source. This class cannot be inherited. |
OdbcErrorCollection | Collects all errors generated by the OdbcDataAdapter. This class cannot be inherited. |
OdbcParameterCollection | Represents a collection of parameters relevant to an OdbcCommand as well as their respective mappings to columns in a DataSet. This class cannot be inherited. |
OleDbDataReader | Provides a way of reading a forward-only stream of data rows from a data source. This class cannot be inherited. |
OleDbErrorCollection | Collects all errors generated by the .NET Framework Data Provider for OLE DB. This class cannot be inherited. |
OleDbParameterCollection | Represents a collection of parameters relevant to an OleDbCommand as well as their respective mappings to columns in a DataSet. |
OracleDataReader | Provides a way of reading a forward-only stream of data rows from a data source. This class cannot be inherited. |
OracleParameterCollection | Represents a collection of parameters relevant to an OracleCommand as well as their respective mappings to columns in a DataSet. This class cannot be inherited. |
PagedDataSource | Encapsulates the properties of the DataGrid control that allow it to perform paging. This class cannot be inherited. |
PermissionSet | Represents a collection that can contain many different types of permissions. |
PrinterSettings.PaperSizeCollection | Contains a collection of PaperSize objects. |
PrinterSettings.PaperSourceCollection | Contains a collection of PaperSource objects. |
PrinterSettings.PrinterResolutionCollection | Contains a collection of PrinterResolution objects. |
PropertyCollection | Contains the properties of a DirectoryEntry. |
PropertyDataCollection | Represents the set of properties of a WMI object. |
PropertyDescriptorCollection | Represents a collection of PropertyDescriptor objects. |
PropertyGrid.PropertyTabCollection | Contains a collection of PropertyTab objects. |
QualifierDataCollection | Represents a collection of QualifierData objects. |
Queue | Represents a first-in, first-out collection of objects. |
ReadOnlyCollectionBase | Provides the abstract (MustInherit in Visual Basic) base class for a strongly typed read-only collection. |
RepeaterItemCollection | Represents a collection of RepeaterItem objects in the Repeater control. This class cannot be inherited. |
ResourceReader | Enumerates .resources files and streams, reading sequential resource name and value pairs. |
ResourceSet | Stores all the resources localized for one particular culture, ignoring all other cultures, including any fallback rules. |
ResXResourceReader | Enumerates XML resource (.resx) files and streams, and reads the sequential resource name and value pairs. |
SchemaNameCollection | Contains a list of the schema names that the SchemaFilter property of a DirectoryEntries object can use. |
SearchResultCollection | Contains the SearchResult instances that the Active Directory hierarchy returned during a DirectorySearcher query. |
SecurityCallers | Provides an ordered collection of identities in the current call chain. |
SelectedDatesCollection | Encapsulates a collection of System.DateTime objects that represent the selected dates in a Calendar control. This class cannot be inherited. |
SharedPropertyGroupManager | Controls access to shared property groups. This class cannot be inherited. |
SignedInfo | Contains information about the canonicalization algorithm and signature algorithm used for the XML signature. |
SortedList | Represents a collection of key-and-value pairs that are sorted by the keys and are accessible by key and by index. |
SqlCeErrorCollection | Collects all errors generated by the .NET Compact Framework Data Provider for SQL Server CE. This class cannot be inherited. |
SqlCeParameterCollection | Collects all parameters relevant to a SqlCeCommand as well as their respective mappings to DataSet columns. |
SqlDataReader | Provides a means of reading a forward-only stream of rows from a SQL Server database. This class cannot be inherited. |
SqlErrorCollection | Collects all errors generated by the .NET Framework Data Provider for SQL Server. This class cannot be inherited. |
SqlParameterCollection | Represents a collection of parameters relevant to a SqlCommand as well as their respective mappings to columns in a DataSet. This class cannot be inherited. |
Stack | Represents a simple last-in-first-out collection of objects. |
StateBag | Manages the view state of ASP.NET server controls, including pages. This class cannot be inherited. |
StatusBar.StatusBarPanelCollection | Represents the collection of panels in a StatusBar control. |
String | Represents text; that is, a series of Unicode characters. |
StringCollection | Represents a collection of strings. |
StringDictionary | Implements a hashtable with the key strongly typed to be a string rather than an object. |
TabControl.TabPageCollection | Contains a collection of TabPage objects. |
TableCellCollection | Encapsulates a collection of TableHeaderCell and TableCell objects that make up a row in a Table control. This class cannot be inherited. |
TableRowCollection | Encapsulates a collection of TableRow objects that represent a single row in a Table control. This class cannot be inherited. |
TempFileCollection | Represents a collection of temporary files. |
ToolBar.ToolBarButtonCollection | Encapsulates a collection of ToolBarButton controls for use by the ToolBar class. |
TraceListenerCollection | Provides a thread-safe list of TraceListener objects. |
TreeNodeCollection | Represents a collection of TreeNode objects. |
TypeConverter.StandardValuesCollection | Represents a collection of values. |
ValidatorCollection | Exposes an array of IValidator references. This class cannot be inherited. |
XmlNamedNodeMap | Represents a collection of nodes that can be accessed by name or index. |
XmlNamespaceManager | Resolves, adds and removes namespaces to a collection and provides scope management for these namespaces. This class is used by the XsltContext and XmlReader classes. |
XmlNode | Represents a single node in the XML document. |
XmlNodeList | Represents an ordered collection of nodes. |
XmlSchemaCollection | Contains a cache of XML Schema definition language (XSD) and XML-Data Reduced (XDR) schemas. This class cannot be inherited. |
Remarks
Notes to Implementers:IEnumerable must be implemented to support the ForEach semantics of Microsoft Visual Basic. COM classes that allow enumerators also implement this interface.
Requirements
Namespace: System.CollectionsPlatforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
Assembly: Mscorlib (in Mscorlib.dll)
No comments:
Post a Comment