A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© sunrise2 高级黑马   /  2014-7-23 23:42  /  602 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Runtime.InteropServices;
  6. using System.IO;

  7. namespace HelloCSharp
  8. {
  9.     //[section]
  10.     //key=value
  11.     //
  12.     class IniHelper
  13.     {
  14.         /// <summary>
  15.         /// ini文件的路径
  16.         /// </summary>
  17.         private string filePath;


  18.         [DllImport("kernel32")]
  19.         private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
  20.         [DllImport("kernel32")]
  21.         private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);

  22.         public IniHelper(string filePath)
  23.         {
  24.             this.filePath = filePath;
  25.         }

  26.         public void IniWriteValue(string section, string key, string val)
  27.         {
  28.             WritePrivateProfileString(section, key, val, filePath);
  29.         }

  30.         public string IniReadValue(string section, string key)
  31.         {
  32.             StringBuilder temp = new StringBuilder(500);
  33.             GetPrivateProfileString(section, key, "", temp, 500, filePath);
  34.             return temp.ToString();
  35.         }
  36.     }
  37. }
复制代码


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马