ResourceReader.IDisposable.Dispose Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Rilascia le risorse usate da ResourceReader.
virtual void System.IDisposable.Dispose() = IDisposable::Dispose;
void IDisposable.Dispose ();
abstract member System.IDisposable.Dispose : unit -> unit
override this.System.IDisposable.Dispose : unit -> unit
Sub Dispose () Implements IDisposable.Dispose
Implementazioni
Esempio
Nell'esempio di codice seguente vengono spostate le risorse di un file e vengono stampate tutte le coppie chiave/valore trovate. Il codice usa quindi il metodoIDisposable.Dispose per arrestare ResourceReader e per rilasciare tutte le risorse usate.
Imports System
Imports System.Resources
Imports System.Collections
Public Class ReadResources
Public Shared Sub Main(args() As String)
' Create a resource reader for items.resources
' and get an enumerator to iterate through the file.
Dim reader As IResourceReader = New ResourceReader("items.resources")
Dim en As IDictionaryEnumerator = reader.GetEnumerator()
' Iterate through the file, printing the key and value pairs.
While en.MoveNext()
Console.WriteLine()
Console.WriteLine("Name: {0}", en.Key)
Console.WriteLine("Value: {0}", en.Value)
End While
' Clean up all resources associated with the reader.
' Calling Dispose is equivalent to calling Close.
reader.Dispose()
End Sub
End Class
using System;
using System.Resources;
using System.Collections;
public class ReadResources
{
public static void Main(string[] args)
{
// Create a resource reader for items.resources
// and get an enumerator to iterate through the file.
IResourceReader reader = new ResourceReader("items.resources");
IDictionaryEnumerator en = reader.GetEnumerator();
// Iterate through the file, printing the key/value pairs.
while (en.MoveNext())
{
Console.WriteLine();
Console.WriteLine("Name: {0}", en.Key);
Console.WriteLine("Value: {0}", en.Value);
}
// Clean up all resources associated with the reader.
// Calling Dispose is equivalent to calling Close.
reader.Dispose();
}
}
using namespace System;
using namespace System::Resources;
using namespace System::Collections;
int main()
{
array<String^>^args = Environment::GetCommandLineArgs();
// Create a resource reader for items.resources
// and get an enumerator to iterate through the file.
IResourceReader^ reader = gcnew ResourceReader( "items.resources" );
IDictionaryEnumerator^ en = reader->GetEnumerator();
// Iterate through the file, printing the key/value pairs.
while ( en->MoveNext() )
{
Console::WriteLine();
Console::WriteLine( "Name: {0}", en->Key );
Console::WriteLine( "Value: {0}", en->Value );
}
// Clean up all resources associated with the reader.
// Calling the destructor is equivalent to calling Close.
reader->~IResourceReader();
}
Commenti
La chiamata a Dispose consente di riallocare le risorse usate da ResourceReader per altri scopi. Per altre informazioni su Dispose, vedere Pulizia delle risorse non gestite.