修改ReadSection方法,将GetPrivateProfileString的第二个参数改为section即可读取指定section下的所有行。

public List ReadSection(string section) { List values = new List(); StringBuilder temp = new StringBuilder(255); int i = GetPrivateProfileString(section, section, "", temp, 255, this.path); //修改此处 string[] sections = temp.ToString().Split('\0'); foreach (string s in sections) { if (!string.IsNullOrEmpty(s)) { values.Add(s); } } return values;

以下这段代码只能读section下的第一行using SystemRuntimeInteropServices;using SystemText;public class IniFile private string path; DllImportkernel32 private static extern long WritePrivateProfileStringstring

原文地址: https://www.cveoy.top/t/topic/cO8e 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录