Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在AppConfig文件中循环_C#_Loops - Fatal编程技术网

C# 在AppConfig文件中循环

C# 在AppConfig文件中循环,c#,loops,C#,Loops,我有一个AppConfig文件,如下所示: <configuration> <configSections> <sectionGroup name="TableSettings"> <section name="TableNames" type="System.Configuration.DictionarySectionHandler"/> </sectionGroup> </configSe

我有一个AppConfig文件,如下所示:

<configuration>
  <configSections>
    <sectionGroup name="TableSettings">
      <section name="TableNames" type="System.Configuration.DictionarySectionHandler"/>
    </sectionGroup>
  </configSections>
  <TableSettings>
    <TableNames>
      <add key="Tablename" value="DailyBilling_20131231"/>
      <add key="Tablename" value="DailyBilling_20130131"/>
    </TableNames>
  </TableSettings>
</configuration>
感谢您的帮助

谢谢。

试试这个

        try
        {
            string strXML = File.ReadAllText("xml.xml");

            XDocument xsrcdoc = XDocument.Parse(strXML);

            var KeyValuePairs = (from xml in xsrcdoc.Descendants("add") select 
                                 new {
                                     Key = xml.Attribute("key").Value,
                                     value = xml.Attribute("value").Value
                                 }).ToList();
        } //Put a break-point here and mouse-over KeyValuePairs and you should see your values....
        catch (Exception)
        {
            throw;
        }

我正在从应用程序构建文件夹中的文件(XML.XML)中将XML读入字符串。要使代码正常工作,请将strXML设置为XML或创建XML.XML文件并将XML保存在其中……

请查看以下问题的答案:
        try
        {
            string strXML = File.ReadAllText("xml.xml");

            XDocument xsrcdoc = XDocument.Parse(strXML);

            var KeyValuePairs = (from xml in xsrcdoc.Descendants("add") select 
                                 new {
                                     Key = xml.Attribute("key").Value,
                                     value = xml.Attribute("value").Value
                                 }).ToList();
        } //Put a break-point here and mouse-over KeyValuePairs and you should see your values....
        catch (Exception)
        {
            throw;
        }