首頁 >後端開發 >C++ >如何在 C# 中存取和循環 .resx 資源?

如何在 C# 中存取和循環 .resx 資源?

Patricia Arquette
Patricia Arquette原創
2024-12-30 12:13:10987瀏覽

How to Access and Loop Through .resx Resources in C#?

在 C# 中存取 .resx 資源

從 .resx 檔案中檢索資源是 C# 局部化的一個重要面向。以下是如何使用 ResourceManager 有效地循環和存取資源:

using System.Collections;
using System.Globalization;
using System.Resources;

ResourceManager resourceManager =
    new ResourceManager(typeof(Resources));

ResourceSet resourceSet =
    resourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);

foreach (DictionaryEntry entry in resourceSet)
{
    string resourceKey = entry.Key.ToString();
    object resourceValue = entry.Value;
}

透過使用 ResourceManager,您可以確保資源的正確全球化和本地化。這種方法可讓您迭代資源集並檢索鍵值對,使您能夠根據目前使用者的文化動態存取資源值。

以上是如何在 C# 中存取和循環 .resx 資源?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn