当前位置: 首页>>代码示例>>C#>>正文


C# ResXResourceReader.GetEnumerator方法代码示例

本文整理汇总了C#中System.Resources.ResXResourceReader.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# ResXResourceReader.GetEnumerator方法的具体用法?C# ResXResourceReader.GetEnumerator怎么用?C# ResXResourceReader.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Resources.ResXResourceReader的用法示例。


在下文中一共展示了ResXResourceReader.GetEnumerator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

//引入命名空间
using System;
using System.Collections;
using System.Resources;

public class Example
{
   private const string resxFilename = @".\CountryHeaders.resx";
    
   public static void Main()
   {
      // Create a resource file to read.
      CreateResourceFile();
      
      // Enumerate the resources in the file.
      ResXResourceReader rr = new ResXResourceReader(resxFilename);
      IDictionaryEnumerator dict = rr.GetEnumerator();
      while (dict.MoveNext())
         Console.WriteLine("{0}: {1}", dict.Key, dict.Value);   
   }

   private static void CreateResourceFile()
   {
      ResXResourceWriter rw = new ResXResourceWriter(resxFilename);
      string[] resNames = {"Country", "Population", "Area", 
                           "Capital", "LCity" };
      string[] columnHeaders = { "Country Name", "Population (2010}", 
                                 "Area", "Capital", "Largest City" };
      string[] comments = { "The localized country name", "", 
                            "The area in square miles", "", 
                            "The largest city based on 2010 data" };
      rw.AddResource("Title", "Country Information");
      rw.AddResource("nColumns", resNames.Length);
      for (int ctr = 0; ctr < resNames.Length; ctr++) {
         ResXDataNode node = new ResXDataNode(resNames[ctr], columnHeaders[ctr]);
         node.Comment = comments[ctr];
         rw.AddResource(node);
      }
      rw.Generate();
      rw.Close();
   }
}
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:42,代码来源:ResXResourceReader.GetEnumerator

输出:

Title: Country Information
nColumns: 5
Country: Country Name
Population: Population (2010}
Area: Area
Capital: Capital
LCity: Largest City

示例2: ResXResourceReader.GetEnumerator()

//引入命名空间
using System;
using System.Globalization;
using System.Resources;
using System.Collections;
using System.Drawing;

class Class1 {
  static void Main(string[] args) {
         ResXResourceWriter RwX = new ResXResourceWriter("Java2s.resx");

         RwX.AddResource("key 1", "First value");
         RwX.AddResource("key 2", "Second value");
         RwX.AddResource("key 3", "Third value");

         // add an image to the resource file
         Image img = Image.FromFile("winter.jpg");
         RwX.AddResource("winter.jpg", img);

         RwX.Generate();
         RwX.Close();

         ResXResourceReader RrX = new ResXResourceReader("Java2s.resx");
         IDictionaryEnumerator RrEn = RrX.GetEnumerator();
         while (RrEn.MoveNext())
         {
            Console.WriteLine("Name: {0} - Value: {1}", 
               RrEn.Key.ToString().PadRight(10, ' '), 
               RrEn.Value);
         }
         RrX.Close();
   }
}
开发者ID:C#程序员,项目名称:System.Resources,代码行数:33,代码来源:ResXResourceReader.GetEnumerator


注:本文中的System.Resources.ResXResourceReader.GetEnumerator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。