深入Resource實現(xiàn)多語言支持的應(yīng)用詳解
首先為假設(shè)有一個應(yīng)用程序CAStudy,接著右鍵添加一個資源文件Resource1.resx。
Resource1.resx里面如下:

Main函數(shù)如下:
static void Main()
{
ResourceManager resourceManager = new ResourceManager(
"CAStudy.Resource1",
Assembly.GetExecutingAssembly());
Console.WriteLine("String1 : " + resourceManager.GetString("String1"));
Console.WriteLine("String1 : " + Resource1.String1);
Console.ReadLine();
}
使用的ResourceManager構(gòu)造函數(shù)如下:
[SecuritySafeCritical]
public ResourceManager(string baseName, Assembly assembly);
在應(yīng)用程序編譯的時候Resource1.resx就會被編譯成Resource1的一個類。所以如果你不知道baseName是什么,也可以這樣:
ResourceManager resourceManager = new ResourceManager(
Resource1.ResourceManager.BaseName,
Assembly.GetExecutingAssembly());
或者你查看IL代碼,可以發(fā)現(xiàn)如下:

運行結(jié)果如下:
![clip_image002[5]](http://img.jbzj.com/file_images/article/201305/20130513173355153.jpg)
![clip_image002[7]](http://img.jbzj.com/file_images/article/201305/20130513173355154.jpg)
那么我們可以復(fù)制Resource1.resx ,從而生成Resource1.en-US.resx。
相關(guān)文章
詳解C# 泛型中的數(shù)據(jù)類型判定與轉(zhuǎn)換
這篇文章主要介紹了C# 泛型中的數(shù)據(jù)類型判定與轉(zhuǎn)換,文中講解非常細致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下2020-07-07
C#基礎(chǔ)語法:Base關(guān)鍵字學(xué)習(xí)筆記
這篇文章主要介紹了C#基礎(chǔ)語法:Base關(guān)鍵字學(xué)習(xí)筆記,本文講解了它的一些基礎(chǔ)知識以及測試代碼,需要的朋友可以參考下2015-06-06
C# 使用HttpClient上傳文件并附帶其他參數(shù)的步驟
這篇文章主要介紹了C# 使用HttpClient上傳文件并附帶其他參數(shù)的步驟,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下2020-12-12

