ResXResourceReader.Close 方法

定義

釋出 ResXResourceReader 所使用的全部資源。Releases all resources used by the ResXResourceReader.

public:
 virtual void Close();
public void Close ();
abstract member Close : unit -> unit
override this.Close : unit -> unit
Public Sub Close ()

實作

範例

下列範例會將檔案的資源顯示到主控台,然後使用 Close 方法來關閉讀取器,並將其資源提供給其他進程使用。The following example displays the resources of a file to the console, and then uses the Close method to shut down the reader and to make its resources available for other processes.

#using <system.windows.forms.dll>
#using <System.dll>

using namespace System;
using namespace System::Resources;
using namespace System::Collections;
void main()
{

   // Create a ResXResourceReader for the file items.resx.
   ResXResourceReader^ rsxr = gcnew ResXResourceReader( "items.resx" );


   // Iterate through the resources and display the contents to the console.
   IEnumerator^ myEnum = rsxr->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      DictionaryEntry^ d = safe_cast<DictionaryEntry^>(myEnum->Current);
      Console::WriteLine( "{0}:\t {1}", d->Key, d->Value );
   }


   //Close the reader.
   rsxr->Close();
}

using System;
using System.Resources;
using System.Collections;

class ReadResXResources
{
   public static void Main()
   {

      // Create a ResXResourceReader for the file items.resx.
      ResXResourceReader rsxr = new ResXResourceReader("items.resx");

      // Iterate through the resources and display the contents to the console.
      foreach (DictionaryEntry d in rsxr)
      {
    Console.WriteLine(d.Key.ToString() + ":\t" + d.Value.ToString());
      }

     //Close the reader.
     rsxr.Close();
   }
}
Imports System.Resources
Imports System.Collections

Class ReadResXResources
   
   Public Shared Sub Main()
      
      ' Create a ResXResourceReader for the file items.resx.
      Dim rsxr As ResXResourceReader
      rsxr = New ResXResourceReader("items.resx")

      ' Iterate through the resources and display the contents to the console.
      Dim d As DictionaryEntry
      For Each d In  rsxr
         Console.WriteLine(d.Key.ToString() + ":" + ControlChars.Tab + d.Value.ToString())
      Next d
      
      'Close the reader.
      rsxr.Close()

   End Sub

End Class

備註

呼叫 Close 可讓 ResXResourceReader 用來重新配置的資源,以供其他用途使用。Calling Close enables the resources used by the ResXResourceReader to be reallocated for other purposes. 如需 Close的詳細資訊,請參閱清除非受控資源For more information about Close, see Cleaning Up Unmanaged Resources.

適用於