.NET框架中是否有可以读/写标准.ini文件的类:
[Section]
<keyname>=<value>
...
Run Code Online (Sandbox Code Playgroud)
Delphi有TIniFile组件,我想知道C#是否有类似内容?
在C#中是否有一种简单的方法来读取属性文件,该文件在单独的行上包含每个属性,后跟等号和值,如下所示:
ServerName=prod-srv1
Port=8888
CustomProperty=Any value
Run Code Online (Sandbox Code Playgroud)
在Java中,Properties类可以轻松处理此解析:
Properties myProperties=new Properties();
FileInputStream fis = new FileInputStream (new File("CustomProps.properties"));
myProperties.load(fis);
System.out.println(myProperties.getProperty("ServerName"));
System.out.println(myProperties.getProperty("CustomProperty"));
Run Code Online (Sandbox Code Playgroud)
我可以轻松地在C#中加载文件并解析每一行,但是有没有内置的方法来轻松获取属性而无需解析密钥名称和等号本身?我发现的C#信息似乎总是支持XML,但这是一个我无法控制的现有文件,我宁愿将其保留为现有格式,因为需要更多时间让其他团队将其更改为XML而不是解析现有的文件.