MenuItemCollection.GetEnumerator Method

Note: This method is new in the .NET Framework version 2.0.

Returns an enumerator that can be used to iterate through the items in the current MenuItemCollection object.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public:
virtual IEnumerator^ GetEnumerator () sealed
public final IEnumerator GetEnumerator ()
public final function GetEnumerator () : IEnumerator

Return Value

An enumerator that can be used to iterate through the items in the current MenuItemCollection.

Use the GetEnumerator method to create an enumerator that can be easily iterated through to get each item in the current MenuItemCollection object. To get the item currently pointed to in the enumerator, use the Current property. Use the MoveNext method to move to the next item. If you need to move the enumerator back to the beginning of the collection, use the Reset method.

NoteNote

After you create an enumerator or use the Reset method, you must call the MoveNext method. Otherwise, the item represented by the Current property is undefined.

As an alternative, you can also use the CopyTo method to copy the items in the collection to an array. You can then use the array to access the items in the collection.

The following code example demonstrates how to use the GetEnumerator method to create an enumerator that contains the submenu items of the Music menu item in a Menu control.

No code example is currently available or this language may not be supported.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show: