C# 读写ini配置文件
1、新建类,引入命名空间 using System.Runtime.InteropServices;
2、声明API函数:
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
3、实现:写
/// <summary>
/// 写入INI文件
/// </summary>
/// <param name="field">项目名称(如 [TypeName] )</param>
/// <param name="Key">键</param>
/// <param name="Value">值</param>
public void GetValueOfKey(string field, string Key, string Value)
{
WritePrivateProfileString(field, Key, Value, iniFilePath);
}
4、实现:读
/// <summary>
/// 读出INI文件
/// </summary>
/// <param name="field&#