一段简单加载配置文件的代码

public Setting()

{

            string dirPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Config");
            string[] filePaths = Directory.GetFiles(dirPath, "Database.*config");
            if (filePaths != null || filePaths.Length > 0)
            {
                foreach (string path in filePaths)
                {
                    Load(path);
                }

            }

 }

private void Load(string Path)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(Path);

            XmlNodeList nodes = doc.DocumentElement.SelectNodes("Name");
            foreach (XmlElement elem in nodes)
            {
               string key=elem.GetAttribute("key");
            }
        } 

原文地址:https://www.cnblogs.com/wyxy2005/p/1871623.html