Where to store string messages?

M

martin-g

Hi.

Almost every application have to write out some messages to the user.
The question is how to store them. For example, while programming for
Windows in C++ we could store these messages as string resource and
load them using LoadString API function. I'm quite new to C#, and the
best thing I've managed is creating private constant members of a
class. E. g.:

public class ExpandManager
{

....

#region Message declarations

private const string ERR_NOSUCHFILE = "File not found: ";
private const string ERR_EMPTY = "The selected workbook seems to be
empty.";
private const string ERR_LOCATECOL = "Couldn't locate the column
with area codes.";
private const string MSG_OPEN = "Opening source";
private const string MSG_CALCDIMS = "Obtaining ratelist
dimensions";
private const string MSG_PREPAREOUT = "Preparing output workbook";
private const string MSG_EXPAND = "Expanding code intervals";

#endregion
}

Isn't there an elegant way to solve this issue?

Thanks in advance

Martin
 
T

Truong Hong Thi

Right click the project and select "Add New Item". Select Resources
File. It is essentially an XML file with the resx extension. VS2005
will auto-generate an internal class with the name same as the
resources file, and all you have to do is calling its static
properties. Very easy, try it out.

If you are using VS2003, the IDE does not generate the class for you so
you have to write code to access resources your own with the help of
System.Resources.ResourceManager class.
 
M

martin-g

Truong said:
Right click the project and select "Add New Item". Select Resources
File. It is essentially an XML file with the resx extension. VS2005
will auto-generate an internal class with the name same as the
resources file, and all you have to do is calling its static
properties. Very easy, try it out.

If you are using VS2003, the IDE does not generate the class for you so
you have to write code to access resources your own with the help of
System.Resources.ResourceManager class.

Thank you. I'm using VS2005 and things are really very easy. I wonder
how could have missed this feature :).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top