尹华剑 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 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败