zoukankan      html  css  js  c++  java
  • .net操作InI文件

    public class INI
    {

     public static string IniFileName = "";//路径

    [DllImport("kernel32")]
    private static extern int GetPrivateProfileInt(string lpApplicationName, string lpKeyName, int nDefault, string lpFileName);
    [DllImport("kernel32")]
    private static extern bool GetPrivateProfileString(string lpApplicationName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName);
    [DllImport("kernel32")]
    private static extern bool WritePrivateProfileString(string lpApplicationName, string lpKeyName, string lpString, string lpFileName);
    [DllImport("kernel32")]
    private static extern bool GetPrivateProfileSection(string lpAppName, string lpReturnedString, int nSize, string lpFileName);
    [DllImport("kernel32")]
    private static extern bool WritePrivateProfileSection(string lpAppName, string lpString, string lpFileName);

    public void WriteValue(string Section,string Key,string Value)//对ini文件进行写操作的函数
    {
    WritePrivateProfileString(Section, Key, Value, IniFileName);
    }

    public string ReadValue(string Section, string Key)//对ini文件进行读操作的函数
    {
    StringBuilder temp = new StringBuilder(50000);
    bool b = GetPrivateProfileString(Section, Key, "", temp, temp.Capacity, IniFileName);
    return temp.ToString();
    }

    }

  • 相关阅读:
    Vue.js入门(3)TypeScript
    Dapper源码学习
    .Net中手动实现AOP
    .Net面向对象(OOP)
    Redis实战(18)Redis位图巧用,节约内存
    .Net深拷贝浅拷贝
    .NET面试题系列(22)字符串暂存池(缓冲池)
    .NET面试题系列(二十一)C#中Equals和==的比较
    C# 8.0
    C# 7.0
  • 原文地址:https://www.cnblogs.com/huguole/p/6163637.html
Copyright © 2011-2022 走看看