Why do people consistently recommend using appConfig instead of using Settings files? (.NET)

后端 未结 7 639
谎友^
谎友^ 2021-01-30 05:30

Very often I see the answer to the question like: \"How should I store settings in my .NET app?\" is to edit the app.config file by manually adding entries to the app.config (or

7条回答
  •  难免孤独
    2021-01-30 06:02

    Incorrect: Part of the problem with the settings file approach is that it requires the app to be in a specific place and the settings file to be in the correct place. If one of these gets accidentally moved, then the settings can be lost for good, same as if it gets deleted. There could also be the issue of multiple settings files with the same name in the folder, causing one to be overwritten. This is particularly bad if the software is dependent on the settings file. These problems aren't nearly as pronounced with installed software, but in software which isn't installed, but simply downloaded and run it can be a major issue. Imagine if someone downloaded several of these programs to the same directory and they all used the same settings file name.

    EDIT: As discussed with the person who asked the question, this answer is incorrect because the question is referring to two different ways of saving to a settings file. When I gave my answer, I was thinking that he was referring to two different files. About the only other answer I can provide is that it's a matter of personal preference.

提交回复
热议问题