码迷,mamicode.com
首页 > 其他好文 > 详细

调用Config.ini类

时间:2015-08-25 18:21:33      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

private static string sPath = @Directory.GetCurrentDirectory() + "\\config.ini";
[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 static void Writue(string section, string key, string value)
{
// section=配置节,key=键名,value=键值,path=路径
WritePrivateProfileString(section, key, value, sPath);
}

public static string ReadValue(string section, string key)
{
// 每次从ini中读取多少字节
System.Text.StringBuilder temp = new System.Text.StringBuilder(255);
// section=配置节,key=键名,temp=上面,path=路径
GetPrivateProfileString(section, key, "", temp, 255, sPath);
return temp.ToString(); //注意类型的转换
}

 

比如

int Forecast = Convert.ToInt32(iniSet.ReadValue("1", "1"));

调用Config.ini类

标签:

原文地址:http://www.cnblogs.com/panjuan/p/4757643.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!