ResourceSet.GetEnumerator メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
IDictionaryEnumerator を反復処理できる ResourceSet を返します。
public:
virtual System::Collections::IDictionaryEnumerator ^ GetEnumerator();
public virtual System.Collections.IDictionaryEnumerator GetEnumerator ();
[System.Runtime.InteropServices.ComVisible(false)]
public virtual System.Collections.IDictionaryEnumerator GetEnumerator ();
abstract member GetEnumerator : unit -> System.Collections.IDictionaryEnumerator
override this.GetEnumerator : unit -> System.Collections.IDictionaryEnumerator
[<System.Runtime.InteropServices.ComVisible(false)>]
abstract member GetEnumerator : unit -> System.Collections.IDictionaryEnumerator
override this.GetEnumerator : unit -> System.Collections.IDictionaryEnumerator
Public Overridable Function GetEnumerator () As IDictionaryEnumerator
戻り値
この ResourceSet の IDictionaryEnumerator。
- 属性
例外
リソース セットは、既に閉じられているか破棄されています。
例
次の例では、 ファイルitems.resources
の をResourceSetrs
作成する方法を示します。 次に、 メソッドを GetEnumerator 使用して の を IDictionaryEnumerator 作成します rs
。 は IDictionaryEnumerator 反復処理を行 rs
い、内容をコンソールに表示します。
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();
}
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();
}
}
Imports System.Resources
Imports System.Collections
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
注釈
列挙子は、コレクションのデータの読み取りのみを許可します。 列挙子を使用して、基になるコレクションを変更することはできません。
最初、列挙子はコレクションの先頭の要素の前に位置付けられます。 また、Reset メソッドは、列挙子を最初の位置に戻します。 この位置で Current を呼び出すと、例外がスローされます。 そのため、MoveNext の値を読み取る前に、Current を呼び出して列挙子をコレクションの最初の要素に進める必要があります。
Current は、MoveNext または Reset が呼び出されるまでは同じオブジェクトを返します。 MoveNext は、Current を次の要素に進めます。
列挙子は、コレクションの末尾を越えると、コレクションの最後の要素の後に位置付けられるので、MoveNext を呼び出すと false
が返されます。 前回 MoveNext を呼び出して false
が返された場合に、Current を呼び出すと例外がスローされます。 コレクションの先頭の要素に再び Current を設定するには、先に Reset を呼び出してから MoveNext を呼び出します。
列挙子は、コレクションが変更されない限り有効です。 要素の追加、変更、削除など、コレクションに変更が加えられた場合、列挙子は回復不能に無効になり、次に を呼び出すか、 InvalidOperationExceptionをResetMoveNextスローします。 MoveNext を呼び出してから Current を呼び出すまでの間にコレクションが変更された場合、列挙子は無効になっていても、Current は設定されている要素を返します。
プロパティを使用して、 IDictionaryEnumerator.Entry 現在の要素に格納されている値にアクセスできます。 プロパティを IDictionaryEnumerator.Key 使用して、現在の要素のキーにアクセスします。 プロパティを IDictionaryEnumerator.Value 使用して、現在の要素の値にアクセスします。
列挙子はコレクションに排他アクセスできないため、コレクションの列挙処理は本質的にスレッド セーフな処理ではありません。 コレクションが同期されている場合でも、他のスレッドがコレクションを変更する場合があるため、列挙子が例外をスローする原因になります。 列挙処理を確実にスレッド セーフに行うには、列挙中にコレクションをロックするか、他のスレッドによって行われた変更によってスローされる例外をキャッチします。
適用対象
.NET
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示