Reading/writing an INI file

后端 未结 16 2662
南旧
南旧 2020-11-22 00:15

Is there any class in the .NET framework that can read/write standard .ini files:

[Section]
=
...

Delphi has th

16条回答
  •  庸人自扰
    2020-11-22 01:10

    This article on CodeProject "An INI file handling class using C#" should help.

    The author created a C# class "Ini" which exposes two functions from KERNEL32.dll. These functions are: WritePrivateProfileString and GetPrivateProfileString. You will need two namespaces: System.Runtime.InteropServices and System.Text.

    Steps to use the Ini class

    In your project namespace definition add

    using INI;
    

    Create a INIFile like this

    INIFile ini = new INIFile("C:\\test.ini");
    

    Use IniWriteValue to write a new value to a specific key in a section or use IniReadValue to read a value FROM a key in a specific Section.

    Note: if you're beginning from scratch, you could read this MSDN article: How to: Add Application Configuration Files to C# Projects. It's a better way for configuring your application.

提交回复
热议问题