写一个操作 .ini文件的类

点点圈 提交于 2020-01-16 01:25:08

class IniHelp
{
private string iniPath;
[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);
public IniHelp(string iniPath)
{
this.iniPath = iniPath;
}
public IniHelp()
{

}
public void setFilePath(string filePath)
{
this.iniPath = filePath;

}
public void iniWrite(string section,string key,string val)
{
WritePrivateProfileString(section,key,val,iniPath);
}
public string iniReadValue(string section,string key)
{
StringBuilder temp=new StringBuilder(500);
int i=GetPrivateProfileString(section,key,"",temp,500,iniPath);
return temp.ToString();
}
public bool existIniFile()
{
return File.Exists(iniPath);
}

}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!