C#程序读取ini文件,以便外部修改参数

方法如下:

using System.Runtime.InteropServices;       

 #region

        [DllImport("kernel32")]

        private static extern int GetPrivateProfileString(string section, string key, string defVal, StringBuilder retVal, int size, string filePath);

        #endregion

读取方法如下:

            string fileName = Application.StartupPath + "\\" + "Config.ini";

            StringBuilder temp1 = new StringBuilder(500);

            GetPrivateProfileString("title", "temp0", "为空的时候输出", temp1, 500, fileName);

            输出temp1;

ini文档格式:

[title]
temp0 = 2

 

你可能感兴趣的:(快捷读取ini文件)