ResXResourceReader.Close 方法

定义

释放该 ResXResourceReader命令使用的所有资源。

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

实现

示例

以下示例向控制台显示文件的资源,然后使用 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 资源能够重新分配用于其他目的。 有关详细信息 Close,请参阅 清理非托管资源

适用于