Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ConfigurationManager.AppSettings["SettingName"] vs Properties.Settings.Default.SettingName when should I use each?

Tags:

What should dictate when I should use the configurationManager.AppSettings or the strongly typed settings that visual studio generates? The strongly typed ones seem much more appropriate in most cases, but I suppose that it would be possible to add settings dynamically to a deployed application using the ConfigurationManager approach, but are there any guidelines under which circumstances each is designed to be used?

like image 203
Sam Holder Avatar asked Dec 16 '09 12:12

Sam Holder


2 Answers

From what I read, looks like AppSettings is the older way of doing things. MSDN docs states that user settings can be written at run time if you are using settings.

I always prefer strongly typed settings, which can be implemented with ConfigSection handlers.

Pros and cons of appSettings vs applicationSettings (.NET app.config)

like image 74
ram Avatar answered Sep 21 '22 17:09

ram


The biggest difference is that the generated properties are readonly, so the main reason to use AppSettings is if you want to write them (which is rare).

And yes, you could use AppSettings for dynamicaly generated settings but that is rare too.

like image 45
Henk Holterman Avatar answered Sep 18 '22 17:09

Henk Holterman