黑马程序员技术交流社区
标题:
C#访问配置文件
[打印本页]
作者:
sunrise2
时间:
2014-7-23 23:42
标题:
C#访问配置文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
namespace HelloCSharp
{
//[section]
//key=value
//
class IniHelper
{
/// <summary>
/// ini文件的路径
/// </summary>
private string filePath;
[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 IniHelper(string filePath)
{
this.filePath = filePath;
}
public void IniWriteValue(string section, string key, string val)
{
WritePrivateProfileString(section, key, val, filePath);
}
public string IniReadValue(string section, string key)
{
StringBuilder temp = new StringBuilder(500);
GetPrivateProfileString(section, key, "", temp, 500, filePath);
return temp.ToString();
}
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2