/// <summary> /// 读取或创建配置文件 /// </summary> /// <param name="filename">配置文件名</param> /// <returns>ConfigFile对象</returns> public static ConfigFileHelper LoadOrCreateFile(string filename) { if (!File.Exists(filename)) { var config = new ConfigFileHelper { FileName = filename }; config.CreateFile(); return(config); } return(LoadFile(filename)); }
static RichTextBoxHelper() { //读取配置文件关键字 // 使用GetConfigValueXXX方法读取特定类型的数据 //创建或载入配置文件 var noticesconfig = ConfigFileHelper.LoadOrCreateFile("notices.config"); List <string> keycharlist = new List <string>(); keycharlist.Add(noticesconfig["income"]); keycharlist.Add(noticesconfig["uncome"]); for (int i = 0; i < 999; i++) { var s = noticesconfig["keychar" + (i + 1)]; if (s == string.Empty) { break; } keycharlist.Add(s); } keychar = keycharlist.ToArray(); }