C # INI file read-write simple package

Source: Internet
Author: User

First, the story line

INI file is a very useful configuration file, through the system API can easily manage parameters, this article describes the C # file read and write methods.

Second, the file format

Usually the INI file is in this format:

[Section1]

Key1=value1

Key2=value2

[Section2]

Key3=value3

Key4=value4

Section identification block, a simple grouping

Key~value corresponding key-value pairs

Third, the system API

[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);

DllImport referencing the system API

Iii. Introduction to Usage (package)

public static string Inireadvalue (String section            , String key            , String iniPath) {    StringBuilder temp = new Stri Ngbuilder (+);    int i = getprivateprofilestring (section, Key, "", temp, $, iniPath);    Return temp. ToString ();}

public static void Iniwritevalue (String section
       , String key
, String value
, String IniPath)
{
WritePrivateProfileString (section, key, value, IniPath);
}

This package I have been using, very convenient.

C # INI file read-write simple package

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.