收藏 分销(赏)

C#操作INI文件的类.doc

上传人:仙人****88 文档编号:11731399 上传时间:2025-08-11 格式:DOC 页数:3 大小:26KB 下载积分:10 金币
下载 相关 举报
C#操作INI文件的类.doc_第1页
第1页 / 共3页
C#操作INI文件的类.doc_第2页
第2页 / 共3页


点击查看更多>>
资源描述
// //INIClass.cs using System; using System.Collections.Generic; using System.Text; namespace BoitBoy.MyFile {     /// <summary>     /// INI设置文件类     /// </summary>     public class INIClass     {         public string inipath;         /// <summary>         /// 分隔符         /// </summary>         public static String SpeatorString = “,-,”;         [System.Runtime.InteropServices.DllImport("kernel32")]         private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);         [System.Runtime.InteropServices.DllImport("kernel32")]         private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);         /// <summary>         /// 构造方法         /// </summary>         /// <param name=”INIPath”>文件路径</param>         public INIClass(string INIPath)         {             inipath = INIPath;         }         /// <summary>         /// 写入INI文件         /// </summary>         /// <param name=”Section”>项目名称(如 [TypeName] )</param>         /// <param name=”Key”>键</param>         /// <param name=”Value”>值</param>         public void IniWriteValue(string Section, string Key, object Value)         {             if (Value == null)                 return;             if (Value.GetType() != typeof(System.Collections.ArrayList))                 WritePrivateProfileString(Section, Key, Value.ToString(), this.inipath);             else             {                 System.Collections.ArrayList TempArray = Value as System.Collections.ArrayList;                 String StringValue = “”;                 if (TempArray != null)                 {                     foreach (object Temp in TempArray)                     {                         StringValue += Temp.ToString() + SpeatorString;                     }                 }                 IniWriteValue(Section, Key, StringValue);             }         }         /// <summary>         /// 读出INI文件         /// </summary>         /// <param name=”Section”>项目名称(如 [TypeName] )</param>         /// <param name=”Key”>键</param>         public string IniReadValue_S(string Section, string Key)         {             StringBuilder temp = new StringBuilder(500);             int i = GetPrivateProfileString(Section, Key, “”, temp, 500, this.inipath);             return temp.ToString();         }         public double IniReadValue(string Section, string Key)         {             String Temp = IniReadValue_S(Section, Key);             double temp = 0;             double.TryParse(Temp, out temp);             return temp;         }         public int IniReadValue_I(string Section, string Key)         {             String Temp = IniReadValue_S(Section, Key);             int temp = 0;             int.TryParse(Temp, out temp);             return temp;         }         /// <summary>         /// 读物数组         /// </summary>         /// <param name=”Section”></param>         /// <param name=”Key”></param>         /// <returns></returns>         public System.Collections.ArrayList IniReadValue_A(string Section, string Key)         {             String Value = IniReadValue_S(Section, Key);             String[] Splitor = new String[1];             Splitor[0] = SpeatorString;             String[] Values = Value.Split(Splitor, StringSplitOptions.RemoveEmptyEntries);             System.Collections.ArrayList Back = new System.Collections.ArrayList();             foreach (String Temp in Values)             {                 Back.Add(Temp);             }             return Back;         }         /// <summary>         /// 验证文件是否存在         /// </summary>         /// <returns>布尔值</returns>         public bool ExistINIFile()         {             return System.IO.File.Exists(inipath);         }     } }
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服