欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

写一个操作 .ini文件的类

程序员文章站 2022-06-21 09:50:25
class IniHelp { private string iniPath; [DllImport("kernel32")] private static extern long WritePrivateProfileString(string section, string key, strin ......

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);
}

}