首页 > 学院 > 开发设计 > 正文

C#访问配置文件

2019-11-17 03:09:42
字体:
来源:转载
供稿:网友

C#访问配置文件

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Runtime.InteropServices;using System.IO;namespace HelloCSharp{    //[section]    //key=value    //    class IniHelper    {        /// <summary>        /// ini文件的路径        /// </summary>        PRivate string filePath;        [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 IniHelper(string filePath)        {            this.filePath = filePath;        }        public void IniWriteValue(string section, string key, string val)        {            WritePrivateProfileString(section, key, val, filePath);        }        public string IniReadValue(string section, string key)        {            StringBuilder temp = new StringBuilder(500);            GetPrivateProfileString(section, key, "", temp, 500, filePath);            return temp.ToString();        }    }}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表