概要
cscの作法、調べてみた。
練習問題やってみた。
練習問題
System.Resourcesを使え。
サンプルコード
using System;
using System.Collections;
using System.Drawing;
using System.Resources;
public class Example {
private static void CreateResXFile() {
Bitmap logo = new Bitmap(@".\cat.bmp");
ResXDataNode node;
ResXResourceWriter rw = new ResXResourceWriter(@".\StoreResources.resx");
node = new ResXDataNode("Logo", logo);
node.Comment = "The corporate logo.";
rw.AddResource(node);
rw.AddResource("AppTitle", "Store Locations");
node = new ResXDataNode("nColumns", 5);
node.Comment = "The number of columns in the Store Location table";
rw.AddResource(node);
rw.AddResource("City", "City");
rw.AddResource("State", "State");
rw.AddResource("Code", "Zip Code");
rw.AddResource("Telephone", "Phone");
rw.Generate();
rw.Close();
}
public static void Main() {
CreateResXFile();
ResXResourceSet resSet = new ResXResourceSet(@".\StoreResources.resx");
IDictionaryEnumerator dict = resSet.GetEnumerator();
while (dict.MoveNext())
{
string key = (string) dict.Key;
if (dict.Value is string)
Console.WriteLine("{0}: {1}", key, resSet.GetString(key));
else
Console.WriteLine("{0}: {1}", key, resSet.GetObject(key));
}
}
}
実行結果
>res0
Telephone: Phone
Code: Zip Code
State: State
City: City
nColumns: 5
AppTitle: Store Locations
Logo: System.Drawing.Bitmap
以上。