Defining and using C# application settings

One way to define those values that are pseudo-hardcoded – like a server’s IP address – is to place this in the project setting configuration file.

This is retrieved from the project’s settings:

Define a setting thru visual studio

Define a setting thru visual studio

When saved, these settings are placed in a configuration file.  There are actually two files: app.config (which is found with the source code) and <exe>.config – which is found in the bin/debug directory.

The configuration file in bin/debug directory

The configuration file in bin/debug directory

Application settings in config file

Application settings in config file

Now, to retrieve these settings, its as simple as using the Properties namespace, which are available at runtime:

 sMsgqIP = TestReadXml.Properties.Settings.Default.msgqIP;

N.B.: TestReadXml is the project name

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: