ini檔是常見的設定檔格式,可參考:https://en.wikipedia.org/wiki/INI_file

讀取檔案很容易直覺想到StreamReader

但其實可以用win32 API有效率的讀寫.ini檔哦

 

  • using System.Runtime.InteropServices;
  • 在class中新增下列code

[DllImport( "kernel32", CharSet = CharSet.Unicode, SetLastError = true )] 
private static extern bool WritePrivateProfileString( string sectionName, string keyName, string keyValue, string filePath );
[DllImport( "kernel32", CharSet = CharSet.Unicode, SetLastError = true )]
private static extern int GetPrivateProfileString( string sectionName, string keyName, string defaultReturnString, StringBuilder returnString, int returnStringLength, string filePath );

PS:WritePrivateProfileString中filePath若沒有寫全路徑似乎會指到C:\windows去


 

 

arrow
arrow
    文章標籤
    C# ini
    全站熱搜

    Milexz 發表在 痞客邦 留言(0) 人氣()