Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在visualc中编辑Ini文件#_C#_Ini - Fatal编程技术网

C# 在visualc中编辑Ini文件#

C# 在visualc中编辑Ini文件#,c#,ini,C#,Ini,我试图用它来编辑一个ini,但我似乎无法获得代码来将ini文件的部分添加到RichTextbox中 if (myIni.GetSection(String.Format("[{0}]", comboBox1.SelectedItem.ToString().ToUpper())) != null); { mySection = new IniFile.IniSection(myIni, String.Format("{0}", comboBo

我试图用它来编辑一个ini,但我似乎无法获得代码来将ini文件的部分添加到RichTextbox中

        if (myIni.GetSection(String.Format("[{0}]", comboBox1.SelectedItem.ToString().ToUpper())) != null);
        {
            mySection = new IniFile.IniSection(myIni, String.Format("{0}", comboBox1.SelectedItem.ToString().ToUpper()));
            foreach (IniFile.IniSection.IniKey key in mySection.Keys)
            {
                richTextBox1.AppendText(String.Format("{0}={1}{2}", key.Name, key.Value, Environment.NewLine));
            }
        }

我不知道我的代码有什么问题。

您可以从windows使用旧的现有ini调用:

[System.Runtime.InteropServices.DllImport("kernel32")]
static extern int GetPrivateProfileString(string section,
        string key, string def, StringBuilder retVal,
        int size, string filePath);
[System.Runtime.InteropServices.DllImport("kernel32")]
static extern long WritePrivateProfileString(string section,
        string key, string val, string filePath);


你调试过了吗?
mySection
是否有任何问题?
mySection.key
是否包含数据?@RonBeyer如何检查?使用调试器?这是c#编程基础…@RonBeyer的意思是使用控制台、Writeline或IDE(visual studio)的调试功能来检查mySection是否包含正确的数据似乎
mySection
的值是
{IniFile.IniSection}
mySection.Keys
的值是
{System.Collections.Hashtable.ValueCollection}
StringBuilder temp = new StringBuilder(255);
GetPrivateProfileString("section", "key", "default", temp, 255, inifilename);
String value = temp.ToString();


WritePrivateProfileString("section", "key", value, inifilename);