using System; using System.Resources; class Program { static void Main(string[] args) { // Accessing the 'Messages.resx' file ResourceManager resourceManager = new ResourceManager("Messages", typeof(Program).Assembly); // Retrieving the 'Welcome' string resource string welcomeMessage = (string)resourceManager.GetObject("Welcome"); // Printing the string to console Console.WriteLine(welcomeMessage); } }
using System; using System.Drawing; using System.Resources; class Program { static void Main(string[] args) { // Accessing the 'Icons.resx' file ResourceManager resourceManager = new ResourceManager("Icons", typeof(Program).Assembly); // Retrieving the image resource with key 'Print' Image printIcon = (Image)resourceManager.GetObject("Print"); // Displaying the image in a PictureBox control PictureBox pictureBox = new PictureBox(); pictureBox.Image = printIcon; pictureBox.SizeMode = PictureBoxSizeMode.AutoSize; pictureBox.Show(); } }In this example, we accessed the 'Icons.resx' file and retrieved an image resource with the key 'Print' using GetObject() method. We then displayed the image in a PictureBox control. These examples use the System.Resources.ResourceManager class from the .NET Standard Library.