尹华剑 2023-01-17 14:06 采纳率: 42.9%
浏览 18
已结题

C#读取App.Config的问题

App.Config代码如下,我想将gitStorPath的内容读取出来放到List中,请问如何操作?

</appSettings>

<gitStorList>
    <gitStorPath>C:\1</gitStorPath>
    <gitStorPath>C:\2</gitStorPath>
    <gitStorPath>C:\3</gitStorPath>
</gitStorList>
  • 写回答

1条回答 默认 最新

  • 临风而眠 2023-01-17 14:16
    关注

    用 .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);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 1月25日
  • 已采纳回答 1月17日
  • 创建了问题 1月17日

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?