Erik
Erik

Reputation: 1

C#: Cannot figure out how to use resource file in project

I need to create a resource file for my projects to hold a couple of messages as strings and have tried to figure out how they work.

I've created a new resource file in "project -> properties -> resources" and created an entry with:

Name = fooBar and Value = barFoo

I can now see Resources.resx in SolutionExplorer under my project name ConsoleApplication2

This is where I've come to a stop, I can't find sufficient information on how to use my string in the project. I'd like to be able to do something like:

Console.WriteLine(Something.Something.fooBar)

What namespaces have to start at the beginning? How do I access the string within my project?

I'm using VS2013 Ultimate if that's of any importance

Upvotes: 0

Views: 385

Answers (3)

Latha
Latha

Reputation: 225

Get the namespace from Resources1.Designer.cs file. Add this namespace reference in your file with using statement. Then you can directly use .fooBar to get the value.

Upvotes: 0

toadflakz
toadflakz

Reputation: 7944

The Properties folder under your project works like a namespace, so you need to add a using or reference it as follows:

<project namespace>.Properties.Resources

Upvotes: 0

Ghasem
Ghasem

Reputation: 15563

Use it like this:

Properties.Resources.fooBar

Upvotes: 2

Related Questions