我有一个控制台应用程序,我想在其中写一个文件的名称.
Process.Start("blah.bat");
Run Code Online (Sandbox Code Playgroud)
通常情况下,我会通过写文件的名称在Windows应用程序类似的东西'blah.bat'来设置文件属性.
但是,在这里我没有找到任何设置文件,我添加了一个app.config用于相同的目的.
我不知道在app.config中写什么,这将导致我实现与Windows窗体类似的东西.
例如:在Windows窗体中.Process.Start(Properties.Settings.Default.BatchFile);
where BatchFile是属性中设置文件中的字符串.
xxb*_*bcc 186
您可以System.Configuration在项目中添加引用,然后:
using System.Configuration;
然后
string sValue = ConfigurationManager.AppSettings["BatchFile"];
使用这样的app.config文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="BatchFile" value="blah.bat" />
</appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
对于.NET Core,请从NuGet管理器中添加System.Configuration.ConfigurationManager。
并从App.config中读取appSetting
<appSettings>
<add key="appSetting1" value="1000" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)
从NuGet Manager添加System.Configuration.ConfigurationManager
ConfigurationManager.AppSettings.Get("appSetting1")
Run Code Online (Sandbox Code Playgroud)
小智 5
用这个
System.Configuration.ConfigurationSettings.AppSettings.Get("Keyname")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
161431 次 |
| 最近记录: |