IEnumerator.Currentとは? わかりやすく解説

IEnumerator.Current プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

列挙子の現在位置にあるコレクション内の要素取得します

名前空間: System.Collections.Generic
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
IEnumerator ジェネリック インターフェイス
IEnumerator メンバ
System.Collections.Generic 名前空間
IEnumerator.Current プロパティ
IEnumerator.MoveNext

IEnumerator.Current プロパティ

コレクション内の現在の要素取得します

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

InvalidOperationException

列挙子が、コレクション最初要素の前、または最後要素の後に位置してます。

または

列挙子が作成された後に、コレクション変更されました。

解説解説
使用例使用例

カスタム コレクションでの IEnumerator インターフェイス実装次のコード例示します。この例では、Current明示的に呼び出されていませんが、foreach (Visual Basic では for each) の使用サポートするために実装されています。このコード例は、IEnumerator インターフェイストピック取り上げているコード例一部です。

Public Class PeopleEnum
    Implements IEnumerator

    Public _people() As Person

    ' Enumerators are positioned before the first element
    ' until the first MoveNext() call.
    Dim position As Integer
 = -1

    Public Sub New(ByVal
 list() As Person)
        _people = list
    End Sub

    Public Function MoveNext() As
 Boolean Implements IEnumerator.MoveNext
        position = position + 1
        Return (position < _people.Length)
    End Function

    Public Sub Reset() Implements
 IEnumerator.Reset
        position = -1
    End Sub

    Public ReadOnly Property
 Current() As Object Implements
 IEnumerator.Current
        Get
            Try
                Return _people(position)
            Catch ex As IndexOutOfRangeException
                Throw New InvalidOperationException()
            End Try
        End Get
    End Property
End Class
public class PeopleEnum : IEnumerator
{
    public Person[] _people;

    // Enumerators are positioned before the first element
    // until the first MoveNext() call.
    int position = -1;

    public PeopleEnum(Person[] list)
    {
        _people = list;
    }

    public bool MoveNext()
    {
        position++;
        return (position < _people.Length);
    }

    public void Reset()
    {
        position = -1;
    }

    public object Current
    {
        get
        {
            try
            {
                return _people[position];
            }
            catch (IndexOutOfRangeException)
            {
                throw new InvalidOperationException();
            }
        }
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「IEnumerator.Current」の関連用語

IEnumerator.Currentのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



IEnumerator.Currentのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS