0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

cscの作法 その567

Posted at

概要

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

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?