資源簡介
關于INI文件的讀取寫入類,跟博客配套的。關于INI文件的讀取寫入類,跟博客配套的。
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Runtime.InteropServices;
using?System.IO;
namespace?cReadConfigFile
{
????public?class?INIClass
????{
????????public?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?INIClass(string?INIPath)
????????{
????????????inipath?=?INIPath;
????????}
????????///??
????????///?寫入INI文件?
????????///? ?
????????///?項目名稱(如?[TypeName]?)?
????????///?鍵?
????????///?值?
????????public?void?IniWriteValue(string?Section?string?Key?string?Value)
????????{
????????????WritePrivateProfileString(Section?Key?Value?this.inipath);
????????}
????????///??
????????///?讀出INI文件?
????????///? ?
????????///?項目名稱(如?[TypeName]?)?
????????///?鍵?
????????public?string?IniReadValue(string?Section?string?Key)
????????{
????????????StringBuilder?temp?=?new?StringBuilder(500);
????????????int?i?=?GetPrivateProfileString(Section?Key?““?temp?500?this.inipath);
????????????return?temp.ToString();
?????
評論
共有 條評論