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