Ser*_*pia 5 c# configuration app-config appsettings
var values = new NameValueCollection
{
{ "key", ConfigurationSettings.AppSettings["API-Key"].ToString() },
{ "image", Convert.ToBase64String(File.ReadAllBytes(photo.ToString())) }
};
Run Code Online (Sandbox Code Playgroud)
使用app.config文件的新方法是什么?
Kel*_*sey 17
本ConfigurationManager类System.Configuration:
ConfigurationManager.AppSettings
ConfigurationManager.ConnectionStrings
Run Code Online (Sandbox Code Playgroud)
所以你的代码将改为:
var values = new NameValueCollection
{
{ "key", ConfigurationManager.AppSettings["API-Key"] },
{ "image", Convert.ToBase64String(File.ReadAllBytes(photo.ToString())) }
};
Run Code Online (Sandbox Code Playgroud)
确保添加引用System.Configuration以及usingfor语句System.Configuration.
使用System.Configuration.ConfigurationManager类
string ServerName = System.Configuration.ConfigurationManager.AppSettings["Servername"];
Run Code Online (Sandbox Code Playgroud)
编辑 - 添加
请注意,您可能必须添加对System.Configuration.dll的引用.即使您可以在没有引用的情况下导入命名空间,除非您有引用,否则您将无法访问此类.
| 归档时间: |
|
| 查看次数: |
18114 次 |
| 最近记录: |