App.Config代码如下,我想将gitStorPath的内容读取出来放到List中,请问如何操作?
</appSettings>
<gitStorList>
<gitStorPath>C:\1</gitStorPath>
<gitStorPath>C:\2</gitStorPath>
<gitStorPath>C:\3</gitStorPath>
</gitStorList>
App.Config代码如下,我想将gitStorPath的内容读取出来放到List中,请问如何操作?
</appSettings>
<gitStorList>
<gitStorPath>C:\1</gitStorPath>
<gitStorPath>C:\2</gitStorPath>
<gitStorPath>C:\3</gitStorPath>
</gitStorList>
用 .NET Framework 提供的 ConfigurationManager 类来读取 App.config 文件中的配置信息。
比如可以这样读取 gitStorPath 节点的值:
using System.Configuration;
List<string> gitStorPathList = new List<string>();
// 获取 gitStorList 节点
var gitStorList = ConfigurationManager.GetSection("gitStorList") as XmlNode;
// 遍历 gitStorPath 节点
foreach (XmlNode gitStorPath in gitStorList.ChildNodes)
{
gitStorPathList.Add(gitStorPath.InnerText);
}