美文网首页.NET
.NET 读写.ini文件

.NET 读写.ini文件

作者: 老中医167788 | 来源:发表于2024-08-25 16:17 被阅读0次

    dotnet add package MadMilkman.Ini

    using MadMilkman.Ini;
    using System.Text;
    
    IniFile file = new IniFile(new IniOptions()
    {
        Encoding = new UTF8Encoding(true),
    });
    
    IniSection section = file.Sections.Add("Section name");
    section.TrailingComment.Text = "Section trailing comment";
    IniKey key = section.Keys.Add("Key name", "Key value ");
    key.LeadingComment.Text = "Key leading comment";
    
    var language = file.Sections.Add("语言");
    language.TrailingComment.Text = "应用程序语言";
    var languageHome = language.Keys.Add("language_home", "zh-cn");
    languageHome.LeadingComment.Text = "应用程序首页语言";
    var languageAbout = language.Keys.Add("language_about", "US-en");
    languageAbout.LeadingComment.Text = "应用程序关于页语言";
    
    var dog = file.Sections.Add("狗");
    dog.Keys.Add("耳朵", "两个");
    dog.Keys.Add("腿", "两只");
    dog.Keys.Add("尾巴", "一个");
    dog.Keys.Add("眼睛", "两个");
    
    
    file.Save("config.ini");
    

    预览


    image.png

    相关文章

      网友评论

        本文标题:.NET 读写.ini文件

        本文链接:https://www.haomeiwen.com/subject/odqokjtx.html