读取/写入 INI 文件 [英] Reading/writing an INI file
本文介绍了读取/写入 INI 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
.NET 框架中是否有可以读/写标准 .ini 文件的类:
Is there any class in the .NET framework that can read/write standard .ini files:
[Section]
<keyname>=<value>
...
Delphi 有 TIniFile
组件,我想知道 C# 是否有类似的东西?
Delphi has the TIniFile
component and I want to know if there is anything similar for C#?
推荐答案
.NET 框架的创建者希望您使用基于 XML 的配置文件,而不是 INI 文件.所以不,没有读取它们的内置机制.
The creators of the .NET framework want you to use XML-based config files, rather than INI files. So no, there is no built-in mechanism for reading them.
不过,有第三方解决方案可用.
There are third party solutions available, though.
- INI 处理程序可以作为 NuGet 包 获得,例如 INI 解析器.
- 您可以编写自己的 INI 处理程序,这是一种老派、费力的方法.它使您可以更好地控制实现,您可以将其用于好坏.见例如使用 C#、P/Invoke 和 Win32 的 INI 文件处理类.
- INI handlers can be obtained as NuGet packages, such as INI Parser.
- You can write your own INI handler, which is the old-school, laborious way. It gives you more control over the implementation, which you can use for bad or good. See e.g. an INI file handling class using C#, P/Invoke and Win32.
这篇关于读取/写入 INI 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文