Strokes.GetEnumerator 方法
傳回物件,這個物件會實作 IEnumerator 介面,並且能逐一查看 Strokes 集合內的 Stroke 物件。
命名空間: Microsoft.Ink
組件: Microsoft.Ink (在 Microsoft.Ink.dll 中)
語法
'宣告
Public Function GetEnumerator As Strokes..::.StrokesEnumerator
'用途
Dim instance As Strokes
Dim returnValue As Strokes..::.StrokesEnumerator
returnValue = instance.GetEnumerator()
public Strokes..::.StrokesEnumerator GetEnumerator()
public:
Strokes..::.StrokesEnumerator^ GetEnumerator()
public Strokes..::.StrokesEnumerator GetEnumerator()
public function GetEnumerator() : Strokes..::.StrokesEnumerator
傳回值
型別:Microsoft.Ink.Strokes.StrokesEnumerator
傳回物件,這個物件會實作 IEnumerator 介面,並且能逐一查看 Strokes 集合內的 Stroke 物件。
範例
這些範例示範兩種列舉 Strokes 集合的方式,以便擷取集合中包含的每個 Stroke 物件。Strokes 集合是由 Ink.Strokes 屬性傳回。
這個範例會取得 Strokes 集合的 IEnumerator,並且用它來周遊集合。
Private Sub EnumerateStrokesWithEnumerator(ByVal mInk As Ink)
' access the Strokes property via using statement
' to insure that the object mStrokes is disposed when finished
' Otherwise, you will have a memory leak
Using mStrokes As Strokes = mInk.Strokes
Dim mStrokesEnumerator As IEnumerator = mStrokes.GetEnumerator()
mStrokesEnumerator.Reset()
While (mStrokesEnumerator.MoveNext())
Dim S As Stroke = DirectCast(mStrokesEnumerator.Current, Stroke)
Me.listBoxStrokeId.Items.Add(S.Id)
End While
End Using
End Sub
private void EnumerateStrokesWithEnumerator(Ink mInk)
{
// access the Strokes property via using statement
// to insure that the object mStrokes is disposed when finished
// Otherwise, you will have a memory leak
using (Strokes mStrokes = mInk.Strokes)
{
IEnumerator mStrokesEnumerator = mStrokes.GetEnumerator();
mStrokesEnumerator.Reset();
while (mStrokesEnumerator.MoveNext())
{
Stroke S = (Stroke)mStrokesEnumerator.Current;
this.listBoxStrokeId.Items.Add(S.Id);
}
}
}
這個範例會使用 foreach 陳述式,該陳述式會在內部程式碼中呼叫編譯器 (Compiler) 所產生用來支援該陳述式的 GetEnumerator 方法。
Private Sub EnumerateStrokesWithForEach(ByVal mInk As Ink)
' access the Strokes property via using statement
' to insure that the object mStrokes is disposed when finished
' Otherwise, you will have a memory leak
Using mStrokes As Strokes = mInk.Strokes
For Each S As Stroke In mStrokes
Me.listBoxStrokeId.Items.Add(S.Id)
Next
End Using
End Sub
private void EnumerateStrokesWithForEach(Ink mInk)
{
// access the Strokes property via using statement
// to insure that the object mStrokes is disposed when finished
// Otherwise, you will have a memory leak
using (Strokes mStrokes = mInk.Strokes)
{
foreach (Stroke S in mStrokes)
{
this.listBoxStrokeId.Items.Add(S.Id);
}
}
}
平台
Windows Vista
.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求。
版本資訊
.NET Framework
支援版本:3.0