.NET Framework Picking (3) IENUMERATOR, IENUMERABLE, ICOLLECTION interface, ENUM class

xiaoxiao2021-03-06  117

Learning to IEnumerator interface, and related knowledge

1. The Ienumerator interface supports simple iterations on a collection. (Support for use for Each Syntax) Public Interface IEnumerator

IEnumerator is a base interface for all enumerations. The number of enumerations only allows data in the collection. The number of enumerations cannot be used to modify the base collection.

Initially, the number of enumerated numbers is positioned in front of the first element in the collection. RESET also returns the enumeration number to this location. At this location, calling Current will trigger an exception. Therefore, before reading the value of the CURRENT, MoveNext must be called to advance the enumeration number to the first element of the collection. Current returns the same object before calling MoveNext or RESET. MoveNext Sets Current to the next element.

After passing to the end of the collection, the enumeration number is placed behind the last element in the collection, and the calling MoveNext will return false. If the last time call MoveNext returns false, calling Current will lead to an exception. To set the current to the first element of the collection again, you can call the RESET and then call MoveNext.

As long as the collection remains unchanged, the number will remain valid. If the collection is changed (eg, add, modify, or delete an element), the number of the enumeration will be invalid and unrecoverable, and the next time the next time the call will raise InvalidOperationException. If the collection is modified between MoveNext and Current, even if the number of enumerated is invalid, the Current will return the elements it set.

Members: Current Properties: Get the current elements in the collection. Readonly Property Current As Object MoveNext method: Promote the enumeration number to the next element of the collection. Function MoveNext () AS Boolean Reset method: set the enumeration number to its initial position, which is before the first element in the collection. SUB RESET ()

2.ienumerable

The number of public enumerations supports the simply iteration on the collection.

Public Interface IEnumerable

IENUMERABLE must be implemented to support the Foreach semantics of Microsoft Visual Basic. Allow this interface that the COM class that allows the enumeration.

Members: GetEnumerator: Returns the number of enumerations that can be loopically accessible. Function genumerator () AS IENUMERATOR

3.ICOLLECTION Defines the size, enumeration and synchronization method of all collections.

System.collections.ienumerable system.collections.icollection public interface iCollection Inherits IEnumerable

The iCollection interface is the base connection between the system.collections namespace. IDictionary and ILIST are more dedicated interfaces based on ICollection interfaces. The IDictionary implementation is a collection of key / value, such as the HashTable class. ILIST implementation is a collection of values ​​that can be sorted and can access their members in accordance with the index, such as the ArrayList class. Some collections (such as Queue Class and STACK class) restrict access to its members, they directly implement the ICollection interface. If the iDictionary interface and IList interface do not meet the required collection requirements, new set classes are derived from the iCollection interface to improve flexibility. 4.enum class

Provide the base class for enumeration. System.Object System.valuType System.enum derived class Mustinherit Public Class Enum imports iComparable, iFormattable, iConvertible

转载请注明原文地址:https://www.9cbs.com/read-100277.html

New Post(0)