C# add resource file and read resource files in console application

1.Add resource file  Resource1.resx via add new item in Console Application project;

2.Open Resource1.resx, Add Resource/Add Existing File, add multiple images;

3.Initialize the ResourceManager instance,please pay attention to the ResourceManager's constructor parameter, baseName,it should include the namespace and resource.resx name;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Resources;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.Globalization;
using System.Collections;

namespace ConsoleApp33
{
    class Program
    {
        static void Main(string[] args)
        {
            ShowResourceFile();
            Console.ReadLine();
        }

        static void ShowResourceFile()
        {
            ResourceManager rm = new ResourceManager("ConsoleApp33.Resource1", Assembly.GetExecutingAssembly());
            ResourceSet resourcesSet = rm.GetResourceSet(CultureInfo.CurrentCulture, true, true);
            if(resourcesSet!=null)
            {
                foreach(DictionaryEntry de in resourcesSet)
                {
                    Console.WriteLine($"Key={de.Key},Value={de.Value}");
                }
            }
        }
    }
}

 

你可能感兴趣的:(C# add resource file and read resource files in console application)