標籤:pos like bsp cursor lin 回收 eve tool related
本文執行個體講述了C#實現讀寫ini檔案類。分享給大家供大家參考。具體如下:
這個C#類封裝了對INI設定檔進行操作所需的各種函數,包括讀取索引值、讀取索引值、刪除段落等
using System;using System.Runtime.InteropServices;using System.Text;namespace DotNet.Utilities{ /// <summary> /// INI檔案讀寫類。 /// </summary> public class INIFile { public string path; public INIFile(string INIPath) { path = 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); [DllImport("kernel32")] private static extern int GetPrivateProfileString(string section, string key, string defVal, Byte[] retVal, int size, string filePath); /// <summary> /// 寫INI檔案 /// </summary> /// <param name="Section"></param> /// <param name="Key"></param> /// <param name="Value"></param> public void IniWriteValue(string Section,string Key,string Value) { WritePrivateProfileString(Section,Key,Value,this.path); } /// <summary> /// 讀取INI檔案 /// </summary> /// <param name="Section"></param> /// <param name="Key"></param> /// <returns></returns> public string IniReadValue(string Section,string Key) { StringBuilder temp = new StringBuilder(255); int i = GetPrivateProfileString(Section,Key,"",temp, 255, this.path); return temp.ToString(); } public byte[] IniReadValues(string section, string key) { byte[] temp = new byte[255]; int i = GetPrivateProfileString(section, key, "", temp, 255, this.path); return temp; } /// <summary> /// 刪除ini檔案下所有段落 /// </summary> public void ClearAllSection() { IniWriteValue(null,null,null); } /// <summary> /// 刪除ini檔案下personal段落下的所有鍵 /// </summary> /// <param name="Section"></param> public void ClearSection(string Section) { IniWriteValue(Section,null,null); } }}
希望本文所述對大家的C#程式設計有所協助。
除聲明外,
跑步客文章均為原創,轉載請以連結形式標明本文地址
C#實現讀寫ini檔案類執行個體
本文地址: http://www.paobuke.com/develop/c-develop/pbk23086.html
相關內容C#實現圖片上傳(PC端和APP)儲存及 跨域上傳說明詳解C#中的定時器Timer類及其記憶體回收機制C# FileStream???t?áD′?ê?aC#操作註冊表的方法詳解
C#DT??IIS??μ?framework°?±?o?μ?·?·¨C#的winform控制項命名規範C#調用sql2000預存程序方法小結C#採用Winform實作類別似Android的Listener
C#實現讀寫ini檔案類執行個體