ResourceSet.GetEnumerator メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ResourceSet.GetEnumerator メソッドの意味・解説 

ResourceSet.GetEnumerator メソッド

ResourceSet を反復処理できる IDictionaryEnumerator を返します。

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

<ComVisibleAttribute(False)> _
Public Overridable Function
 GetEnumerator As IDictionaryEnumerator
Dim instance As ResourceSet
Dim returnValue As IDictionaryEnumerator

returnValue = instance.GetEnumerator
[ComVisibleAttribute(false)] 
public virtual IDictionaryEnumerator GetEnumerator ()
[ComVisibleAttribute(false)] 
public:
virtual IDictionaryEnumerator^ GetEnumerator ()
/** @attribute ComVisibleAttribute(false) */ 
public IDictionaryEnumerator GetEnumerator ()
ComVisibleAttribute(false) 
public function GetEnumerator () : IDictionaryEnumerator

戻り値
この ResourceSet の IDictionaryEnumerator。

例外例外
例外の種類条件

InvalidOperationException

この ResourceSet は閉じられています。

解説解説

列挙子は、コレクション内のデータの読み取りだけを許可します。列挙子を使用して基になるコレクションを変更することはできません。

初期状態では、列挙子はコレクションの最初の要素の前に位置しています。Reset を実行した場合も、列挙子はこの位置に戻されます。この位置で Current を呼び出すと、例外がスローされます。したがって、Current の値を読み取る前に、MoveNext を呼び出して、コレクションの最初の要素に列挙子を進める必要があります。

Current は、MoveNext または Reset が呼び出されるまでは同じオブジェクトを返します。MoveNext は、Current を次の要素に設定します。

コレクションの末尾を過ぎると、列挙子はコレクションの最後の要素の後ろに配置され、MoveNext を呼び出すと false が返されます。MoveNext への最後の呼び出しで false が返された場合に、Current を呼び出すと例外がスローされます。Current をコレクションの最初の要素に再び設定するには、Reset を呼び出してから、MoveNext を呼び出します。

列挙子は、コレクションが変更されない限り有効です。要素の追加、変更、削除などの変更がコレクションに対して実行されると、列挙子は回復不可能な無効状態になり、次に MoveNext または Reset を呼び出すと、InvalidOperationException がスローされます。コレクションが MoveNext と Current の間で変更された場合、列挙子が既に無効になっていても、Current は設定した要素を返します。

IDictionaryEnumerator.Entry プロパティを使用して、現在の要素に格納された値にアクセスできます。IDictionaryEnumerator.Key プロパティを使用して、現在の要素のキーにアクセスします。IDictionaryEnumerator.Value プロパティを使用して、現在の要素の値にアクセスします。

列挙子はコレクションへの排他アクセス権を持たないため、コレクションの列挙処理は、本質的にはスレッド セーフな処理ではありません。コレクションが同期されている場合でも、他のスレッドがそのコレクションを変更する可能性はあり、そのような状況が発生すると列挙子は例外をスローします。列挙処理を確実にスレッド セーフに行うには、列挙中にコレクションをロックするか、他のスレッドによって行われた変更によってスローされる例外をキャッチします。

使用例使用例

ファイル items.resources の ResourceSetrs を作成する方法を次の例に示します。次に、GetEnumerator メソッドを使用して rs の IDictionaryEnumerator を作成します。IDictionaryEnumerator は rs を反復処理して、コンソールに内容を表示します。

Imports System
Imports System.Resources
Imports System.Collections
Imports Microsoft.VisualBasic

Class EnumerateResources
   
   Public Shared Sub Main()
      ' Create a ResourceSet for the file items.resources.
      Dim rs As New ResourceSet("items.resources")
      
      
      ' Create an IDictionaryEnumerator to read the data in the ResourceSet.
      Dim id As IDictionaryEnumerator = rs.GetEnumerator()
      
      ' Iterate through the ResourceSet and display the contents to
 the console. 
      While id.MoveNext()
         Console.WriteLine(ControlChars.NewLine + "[{0}] "
 + ControlChars.Tab + "{1}", id.Key, id.Value)
      End While 

      rs.Close()

   End Sub

End Class
using System;
using System.Resources;
using System.Collections;

class EnumerateResources 
{
    public static void Main()
 
    {
        // Create a ResourceSet for the file items.resources.
        ResourceSet rs = new ResourceSet("items.resources");
 

        
        // Create an IDictionaryEnumerator to read the data in the ResourceSet.
        IDictionaryEnumerator id = rs.GetEnumerator(); 

        // Iterate through the ResourceSet and display the contents
 to the console. 
        while(id.MoveNext())
          Console.WriteLine("\n[{0}] \t{1}", id.Key, id.Value); 

        rs.Close();
 
    }
}
using namespace System;
using namespace System::Resources;
using namespace System::Collections;
int main()
{
   
   // Create a ResourceSet for the file items.resources.
   ResourceSet^ rs = gcnew ResourceSet( "items.resources" );
   
   // Create an IDictionaryEnumerator* to read the data in the ResourceSet.
   IDictionaryEnumerator^ id = rs->GetEnumerator();
   
   // Iterate through the ResourceSet and display the contents to the
 console.
   while ( id->MoveNext() )
      Console::WriteLine( "\n [{0}] \t {1}", id->Key, id->Value );

   rs->Close();
}

import System.*;
import System.Resources.*;
import System.Collections.*;

class EnumerateResources
{

    public static void main(String[]
 args)
    {
        // Create a ResourceSet for the file items.resources.
        ResourceSet rs = new ResourceSet("items.resources");

        // Create an IDictionaryEnumerator to read the data in the ResourceSet.
        IDictionaryEnumerator id = rs.GetEnumerator();

        // Iterate through the ResourceSet and display the contents
 to 
        // the console. 
        while (id.MoveNext()) {
            Console.WriteLine("\n[{0}] \t{1}", id.get_Key(), id.get_Value());
        }
        rs.Close();
    } //main 
} //EnumerateResources
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

ResourceSet.GetEnumerator メソッドのお隣キーワード
検索ランキング

   

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



ResourceSet.GetEnumerator メソッドのページの著作権

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

©2026 GRAS Group, Inc.RSS