取得列舉值指向之 Strokes 集合中的 Stroke 物件。
命名空間: Microsoft.Ink
組件: Microsoft.Ink (在 Microsoft.Ink.dll 中)
語法
'宣告
Public ReadOnly Property Current As Stroke
'用途
Dim instance As Strokes..::.StrokesEnumerator
Dim value As Stroke
value = instance.Current
public Stroke Current { get; }
public:
property Stroke^ Current {
Stroke^ get ();
}
/** @property */
public Stroke get_Current()
public function get Current () : Stroke
屬性值
型別:Microsoft.Ink.Stroke
列舉值指向之 Strokes 集合中的 Stroke 物件。
備註
在建立 Strokes.StrokesEnumerator 列舉值或呼叫 Reset 方法之後,必須呼叫 MoveNext 方法將列舉值前移至集合的第一個項目,才能讀取 Current 屬性的值,否則 Current 會是未定義的。
如果上次呼叫 MoveNext 方法傳回 false,則 Current 屬性會擲回例外狀況 (Exception)。如果上次呼叫 MoveNext 方法傳回 false,表示列舉值已經到達 Strokes 集合的結尾。
Current 屬性不會移動列舉值的位置。在呼叫 MoveNext 或 Reset 方法之前,對 Current 屬性的連續呼叫都會傳回相同的物件。
只要集合保持不變,列舉值將保持有效。如果對集合進行變更,例如加入、修改或刪除項目,則列舉值將失效且無法復原。下次呼叫 MoveNext 或 Reset 方法會擲回 InvalidOperationException (英文) 例外狀況。如果在呼叫 MoveNext 方法和呼叫 Current 屬性之間修改了集合,則 Current 屬性會傳回其所設定成的項目,即使列舉值已經失效也一樣。
範例
這些範例示範兩種列舉 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 陳述式,該陳述式會在內部程式碼中呼叫編譯器所產生用來支援該陳述式的 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
請參閱
參考
Strokes.StrokesEnumerator.MoveNext
Strokes.StrokesEnumerator.Reset