使用ConfigurationManager帮助访问应用程序设置

Aar*_*ers 6 .net c# .net-2.0

在.net框架1.1中,我使用

System.Configuration.ConfigurationSettings.AppSettings["name"];
Run Code Online (Sandbox Code Playgroud)

用于应用程序设置 但是在.Net 2.0中,它说ConfigurationSettings已经过时,而是使用ConfigurationManager.所以我把它换成了这个:

System.Configuration.ConfigurationManager.AppSettings["name"];
Run Code Online (Sandbox Code Playgroud)

问题是,在System.Configuration命名空间中找不到ConfigurationManager.我一直在撞墙,试图找出我做错了什么.有人有任何想法吗?

Ser*_*sta 9

您必须引用System.configuration程序集(请注意小写)

我不知道为什么默认情况下不会将此程序集添加到Visual Studio上的新项目中,但每次启动新项目时我都会遇到同样的问题.我总是忘记添加参考.