C#读取INI文件

    class IniFile
    {
        private string pathname;

#region KERNEL32.DLL
        [DllImport("Kernel32.dll")]
        public static extern UInt32 GetPrivateProfileInt(
            string lpAppName,
            string lpKeyName,
            int nDefault,
            string lpFileName
            );
        [DllImport("Kernel32.dll")]
        public static extern UInt32 GetPrivateProfileString(
            string lpAppName,
            string lpKeyName,
            string lpDefault,
            out string lpReturnedString,
            UInt32 nSize,
            string lpFileName
            );
        [DllImport("Kernel32.dll")]
        public static extern bool WritePrivateProfileString(
            string lpAppName,
            string lpKeyName,
            string lpString,
            string lpFileName
            );
#endregion
        public IniFile(string pathname)
        {
            this.pathname = pathname;
        }

        public bool setInt(string szSection, string szKey, int iVal)
        {
            return WritePrivateProfileString(szSection, szKey, iVal.ToString(), pathname);
        }
        public bool setString(string szSection, string szKey, string szVal)
        {
            return WritePrivateProfileString(szSection, szKey, szVal, pathname);
        }

        public UInt32 getInt(string szSection, string szKey, int iDef)
        {
            return GetPrivateProfileInt(szSection, szKey, iDef, pathname);
        }

        public string getString(string szSection, string szKey, string szDef)
        {
            string ret;
            GetPrivateProfileString(szSection, szKey, szDef, out ret, 255, pathname);
            return ret;
        }
    }


 

你可能感兴趣的:(String,C#,Class,ini)