C# 中读写 Ini 文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace WaceManager.Classes
{
public class IniProcess
{
private string path;
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(
string section, string key, string value, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(
string section, string key, string def,
StringBuilder retVal, int size, string filePath);
public IniProcess (string iniPath)
{
this.path = iniPath;
}
public void write(string section, string key, string value)
{
WritePrivateProfileString(section, key, value, this.path);
}
public string read(string section, string key, string defaultValue)
{
StringBuilder temp = new StringBuilder(255);
GetPrivateProfileString(section, key, "", temp, 1024, this.path);
return (temp.Length > 0) ? temp.ToString() : defaultValue;
}
}
}
/* vim: set expandtab tabstop=4 shiftwidth=4: */
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace WaceManager.Classes
{
public class IniProcess
{
private string path;
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(
string section, string key, string value, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(
string section, string key, string def,
StringBuilder retVal, int size, string filePath);
public IniProcess (string iniPath)
{
this.path = iniPath;
}
public void write(string section, string key, string value)
{
WritePrivateProfileString(section, key, value, this.path);
}
public string read(string section, string key, string defaultValue)
{
StringBuilder temp = new StringBuilder(255);
GetPrivateProfileString(section, key, "", temp, 1024, this.path);
return (temp.Length > 0) ? temp.ToString() : defaultValue;
}
}
}
/* vim: set expandtab tabstop=4 shiftwidth=4: */



sohuandyahoo said,
Wrote on February 19, 2008 @ 5:10 am
博主的blog界面挺漂亮的,都用了那些插件啊,尤其是代码高亮这个不错,简洁大方