ConfigurationSettings becomes ConfigurationManager

从ConfigurationSettings到ConfigurationManager
本文介绍了在.NET框架中从ConfigurationSettings类到ConfigurationManager类的变化。随着.NET版本的升级,开发者们现在可以使用ConfigurationManager来读取配置文件(web/app.config)中的设置值,替代了之前的ConfigurationSettings。

In v1.1 we used the ConfigurationSettings class to read values from our configuration files (web/app.config), in .NET 2.0 we now have the ConfigurationManager class.

ConfigurationSettings.AppSettings[”MySetting”];

becomes

ConfigurationManager.AppSettings[”MySetting”]; 

### .NET Configuration Settings and Guidelines In the context of .NET, configuration settings play a crucial role in defining how an application behaves during runtime. These settings can be persisted either through the Windows Registry or serialized into configuration files such as `app.config` or `web.config`. This persistence mechanism allows developers to modify application behavior without recompiling the source code[^2]. #### Persisting Application Settings To persist application settings at runtime within the .NET Framework, one common practice is saving these configurations directly to the registry or serializing them into XML-based configuration files. By leveraging serialization techniques provided by the framework, it becomes straightforward to store complex objects alongside simple key-value pairs. For instance, consider utilizing classes from namespaces like System.Configuration which offer robust support for managing user preferences programmatically: ```csharp using System; using System.Configuration; class Program { static void Main() { var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); // Modify setting value. string newValue = "NewValue"; if (config.AppSettings.Settings["ExampleKey"] != null){ config.AppSettings.Settings["ExampleKey"].Value = newValue; }else{ config.AppSettings.Settings.Add("ExampleKey",newValue); } // Save changes back to file system. config.Save(ConfigurationSaveMode.Modified); Console.WriteLine($"Updated ExampleKey with {newValue}"); } } ``` This snippet demonstrates modifying existing keys inside appSettings section while ensuring any alterations are saved correctly after execution completes. Additionally, when dealing specifically with datasets—objects representing relational data structures—it's worth noting that both .NET Framework SDK tools along with integrated features available via Visual Studio facilitate generating appropriate subclass definitions tailored towards specific requirements efficiently enough so manual coding effort remains minimal where possible.[^1] Performance considerations also arise depending upon chosen methodologies between employing SQL Data Readers versus calling stored procedures equipped output parameters especially concerning scenarios involving numerous concurrent sessions connected against backend databases simultaneously since enabling connection poolings could lead significant improvements under heavy load circumstances up until approximately thirty percentage points better favorably toward latter option mentioned earlier regarding higher stress situations encountered regularly throughout enterprise environments today.[^4] Regarding components' internal interfaces possibly encompassing more than just typical package-private scopes due various architectural decisions made beforehand including potential partition across several assemblies altogether thus necessitating broader accessibility levels beyond mere 'private', there exist cases wherein even though something might appear restricted solely internally still requires greater visibility outside strictly confined boundaries defined initially per se alone yet again highlighting flexibility inherent modern software engineering practices nowadays prevalent amongst professional circles worldwide alike regardless platform choice ultimately selected accordingly based project needs assessed thoroughly ahead time commencement actual development activities commence fully earnest manner indeed![^3]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值