开发者

Is there a C# analogue of java.util.Properties class

Java has a Properties class that is nice for saving basic configuration information, e.g. a gui setting you would like to have persist from one session to the next.开发者_StackOverflow社区 It saves and retrieves key value pairs as I recall and is quite simple to use. I have been looking for an analogue of this in C# but without success. Am I missing it?

If there isn't one, is there anything above and beyond simply saving / reading a custrom text file for saving simple application setting? (Measure of "above and beyond" being simplicity).


If you create a standard .NET project and go to Properties, then go to Settings, then click to create one, you should be able to accomplish what you want there. That will allow you use Properties.Settings which is good for persisting user settings.

If you want application wide settings, the app.config (compiled as MyApplication.exe.config) is the way to go. You can access these settings via ConfigurationManager.AppSettings (requires System.Configuration assembly reference)


System.Configuration.ConfigurationManager is what you're looking for. It allows you to save/read key/value pairs to the app.config/web.config file for your application.

If you want to store user specific data, you can also check out the settings file: Using Settings in C#


Yes. Search for

Properties.Settings


there is the exact solution of what you want. please find the article from here

his code has a bunch of strong points regarding efficiency.

  1. The application does not load the text file in every request. It loads the text file only once to the memory. For the subsequent request, it returns the value directly from the memory. This is much more efficient if your text file contains thousands or more key-value pairs.
  2. Any change in the text file does not require application restart. A file system watcher has been used to keep track of the file state. If it changes, it triggers an event and loads the new changes accordingly to memory so that, you can change the text file in one application/text editor and see the changed effect in the web application.
  3. You are not only able to use it in a web application but also able to use it in any desktop application.

Thanks. Have a nice day.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜