ResourceSet 构造函数

定义

创建 ResourceSet 类的新实例。

重载

ResourceSet()

使用默认属性初始化 ResourceSet 类的新实例。

ResourceSet(Stream)

使用从给定流中读取资源的系统默认的 ResourceSet 来创建 ResourceReader 类的新实例。

ResourceSet(IResourceReader)

使用指定的资源阅读器创建 ResourceSet 类的新实例。

ResourceSet(String)

使用从给定文件打开并读取资源的系统默认的 ResourceSet 来创建 ResourceReader 类的新实例。

ResourceSet()

使用默认属性初始化 ResourceSet 类的新实例。

protected:
 ResourceSet();
protected ResourceSet ();
Protected Sub New ()

适用于

ResourceSet(Stream)

使用从给定流中读取资源的系统默认的 ResourceSet 来创建 ResourceReader 类的新实例。

public:
 ResourceSet(System::IO::Stream ^ stream);
public ResourceSet (System.IO.Stream stream);
[System.Security.SecurityCritical]
public ResourceSet (System.IO.Stream stream);
new System.Resources.ResourceSet : System.IO.Stream -> System.Resources.ResourceSet
[<System.Security.SecurityCritical>]
new System.Resources.ResourceSet : System.IO.Stream -> System.Resources.ResourceSet
Public Sub New (stream As Stream)

参数

stream
Stream

要读取的资源的 Stream。 流应引用现有的资源文件。

属性

例外

stream 不可读。

stream 参数为 null

适用于

ResourceSet(IResourceReader)

使用指定的资源阅读器创建 ResourceSet 类的新实例。

public:
 ResourceSet(System::Resources::IResourceReader ^ reader);
public ResourceSet (System.Resources.IResourceReader reader);
new System.Resources.ResourceSet : System.Resources.IResourceReader -> System.Resources.ResourceSet
Public Sub New (reader As IResourceReader)

参数

reader
IResourceReader

将使用的读取器。

例外

reader 参数为 null

注解

可以使用此构造函数支持使用用户提供的 IResourceReader自定义资源格式。

适用于

ResourceSet(String)

使用从给定文件打开并读取资源的系统默认的 ResourceSet 来创建 ResourceReader 类的新实例。

public:
 ResourceSet(System::String ^ fileName);
public ResourceSet (string fileName);
new System.Resources.ResourceSet : string -> System.Resources.ResourceSet
Public Sub New (fileName As String)

参数

fileName
String

要读取的资源文件。

例外

fileName 参数为 null

示例

下面的代码示例为特定文件定义类的新实例 ResourceSet ,循环访问该文件使用的资源,并将其内容显示到控制台。

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

适用于