ResourceWriter.AddResource Method (String, String)


Adds a string resource to the list of resources to be written.

Namespace:   System.Resources
Assembly:  mscorlib (in mscorlib.dll)

public void AddResource(
	string name,
	string value


Type: System.String

The name of the resource.

Type: System.String

The value of the resource.

Exception Condition

name (or a name that varies only by capitalization) has already been added to this ResourceWriter.


The name parameter is null.


This ResourceWriter has been closed and its hash table is unavailable.

The resource is not written until Generate is called.

You can retrieve the resources written by the AddResource(String, String) method by calling the ResourceManager.GetString method.

The following example uses the AddResource method to add string resources to a ResourceWriter object.

using System;
using System.Resources;
using System.IO;

public class WriteResources 
    public static void Main(string[] args) 
        // Create a file stream to encapsulate items.resources.
        FileStream fs = new FileStream("items.resources", 

        // Open a resource writer to write from the stream.
        IResourceWriter writer = new ResourceWriter(fs);

        // Add resources to the resource writer.
        writer.AddResource("String 1", "First String");
        writer.AddResource("String 2", "Second String");
        writer.AddResource("String 3", "Third String");

        // Write the resources to the stream, and close it.

.NET Framework
Available since 1.1
Return to top