码迷,mamicode.com
首页 > 其他好文 > 详细

C#访问配置文件

时间:2014-05-18 20:16:27      阅读:309      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   c   java   

bubuko.com,布布扣
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();
        }
    }
}
bubuko.com,布布扣

 

C#访问配置文件,布布扣,bubuko.com

C#访问配置文件

标签:style   blog   class   code   c   java   

原文地址:http://www.cnblogs.com/dan-jacky/p/3732524.html

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