共用方式為


Strokes.GetEnumerator Method

Strokes.GetEnumerator Method

Returns an object that implements the System.Collections.IEnumerator Leave Site interface and that can iterate through the Stroke objects within the Strokes collection.

Definition

Visual Basic .NET Public Function GetEnumerator() As StrokesEnumerator
C# public StrokesEnumerator GetEnumerator();
Managed C++ public: StrokesEnumerator* GetEnumerator();

Return Value

Microsoft.Ink.Strokes.StrokesEnumerator. Returns an object that implements the IEnumerator Leave Site interface and that can iterate through the Stroke objects within the Strokes collection.

Examples

[C#]

These C# examples show two ways to iterate over the Strokes collection and get the Id property for each Stroke object in the Ink object, theInk. The Strokes collection is returned by the Ink.Strokes property.

This C# example gets the IEnumerator Leave Site for the Strokes collection.

ArrayList theArrayList = new ArrayList();
// Version using GetEnumerator()
IEnumerator theInkStrokesEnumerator = theInk.Strokes.GetEnumerator();
while (theInkStrokesEnumerator.MoveNext())
{
    Stroke theStroke = (Stroke) theInkStrokesEnumerator.Current;
    theArrayList.Add(theStroke.Id);
}

This C# example uses the foreach statement, which calls the GetEnumerator method in internal code that the compiler generates to support the statement.

ArrayList theArrayList = new ArrayList();
// Version using foreach
foreach (Stroke theStroke in theInk.Strokes)
{
    theArrayList.Add(theStroke.Id);
}

[VB.NET]

These Microsoft® Visual Basic® .NET examples show two ways to iterate over the Strokes collection and get the Id property for each Stroke object in the Ink object, theInk. The Strokes collection is returned by the Ink.Strokes property.

This Visual Basic .NET example gets the IEnumerator Leave Site for the Strokes collection.

'Version using GetEnumerator()
Dim theArrayList As New ArrayList
Dim theStroke As Stroke
Dim theInkStrokesEnumerator As IEnumerator = theInk.Strokes.GetEnumerator()
While (theInkStrokesEnumerator.MoveNext())
    theStroke = theInkStrokesEnumerator.Current
    theArrayList.Add(theStroke.Name)
End While

This Visual Basic .NET example uses the For Each statement, which calls the GetEnumerator method in internal code that the compiler generates to support the statement.

'Version using For Each
Dim theArrayList As New ArrayList
Dim theStroke as Stroke

For Each theStroke In theInk.Strokes
    theArrayList.Add(theStroke.Id)
Next

See Also