方法如下:
using System.Runtime.InteropServices;
#region
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string defVal, StringBuilder retVal, int size, string filePath);
#endregion
读取方法如下:
string fileName = Application.StartupPath + "\\" + "Config.ini";
StringBuilder temp1 = new StringBuilder(500);
GetPrivateProfileString("title", "temp0", "为空的时候输出", temp1, 500, fileName);
输出temp1;
ini文档格式:
[title]
temp0 = 2
#region
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
#endregion
WritePrivateProfileString(Section, Key, Value, Application.StartupPath + "\\Config.ini");
Section是标题