码迷,mamicode.com
首页 > Windows程序 > 详细

c# ini文件操作

时间:2019-06-05 22:00:11      阅读:366      评论:0      收藏:0      [点我收藏+]

标签:节点   tor   ase   文件   conf   nic   int   div   directory   

 

public class INIConfigHelper
    {
        public string Path;     //INI文件名
        [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);

        //声明读写INI文件的API函数     
        public INIConfigHelper(string iniPath)
        {
            Path = iniPath;
        }

        //类的构造函数,传递INI文件名
        public void IniWriteValue(string section, string key, string value)
        {
            WritePrivateProfileString(section, key, value, this.Path);
        }

        //读INI文件         
        public string IniReadValue(string section, string key)
        {
            var temp = new StringBuilder(256);
            int i = GetPrivateProfileString(section, key, "", temp, 256, this.Path);
            return temp.ToString();
        }
    }
private INIConfigHelper configReader = new INIConfigHelper(string.Concat(AppDomain.CurrentDomain.BaseDirectory, "Config\\Counter.ini"));
读取节点:
string section = "time";
                string startTimeStr = configReader.IniReadValue(section, "start");
更新节点:
configReader.IniWriteValue("time", "start", maxTime.ToString("yyyy-MM-dd HH:mm:ss"));

 

c# ini文件操作

标签:节点   tor   ase   文件   conf   nic   int   div   directory   

原文地址:https://www.cnblogs.com/zengwei/p/10981745.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!