如何让这阵+功能正常工作? [英] How to make this array + function to work?

查看:132
本文介绍了如何让这阵+功能正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要我的帮助阵列希望有人能告诉我怎样才能做到这一点...我对C#的WinForms新

I need help with my array hope someone can tell me how I can do this ... I'm new on c# winforms

这是我的函数,这些函数阵是怎么回事,我想张贴在XML文件中的数组

This is my function where the array is going, I'm trying to post the array on XML file

    // ------------------- Functions
    static void XML_Array(string Data_Array)
    {
        String xmlfile = "/XMLFiles/Settings_Data.xml";

        XmlTextWriter xwriter = new XmlTextWriter(xmlfile, Encoding.Unicode);

        xwriter.WriteStartDocument();

        xwriter.WriteStartElement("XMLFILE");

        foreach (KeyValuePair<string, string> kvp in Data_Array)
        {
            String Element_Name = kvp.Key;
            String Element_Value = kvp.Value.ToString();

            xwriter.WriteStartElement(Element_Name);
            xwriter.WriteString(Element_Value);
            xwriter.WriteEndElement();
        }

        xwriter.WriteEndDocument();
        xwriter.Close();

    }

这是我的数组,这里是什么我想做的是,当我按下按钮2到阵列派我的功能,并且功能上添加XML文件

This is my array, here what I'm trying to do is when I press the button2 to send the array on my function, and the function to add the data of array on XML file

    private void button2_Click(object sender, EventArgs e)
    {
        Dictionary<string, string> Data_Array = new Dictionary<string, string>();
        Data_Array.Add("Name", "textBox3.Text"); // Alex
        Data_Array.Add("Year", "textBox4.Text"); // 1988

        XML_Array(Data_Array);
    }



更新:
我怎么能使,如果我的数组是

UPDate: how I can make if my array is

Dictionary<string, string> Data_Array = new Dictionary<string, string>();
Data_Array.Add("Name", textBox3.Text); // Alex
Data_Array.Add("Year", textBox4.Text); // 1988

Data_Array.Add("Birthday", new Dictionary<string, string>());

和生日添加日,月

推荐答案

该方法的签名更改为

static void XML_Array(Dictionary<string, string> Data_Array)

,因为它不是一个字符串词典

由于varg和奥斯丁都评论你应该考虑重命名你的变量,因为它是混乱当一种说法是名称 data_array中,但实际上它是一个词典什么是完全不同类型的集合。你可能想添加文本属性现有的文本框控制的,而不是字符串(带引号)textBox3.Text

As varg and Austin have commented you should consider to rename your variables because it's confusing when an argument is names Data_Array but actually it is a Dictionary what is a completely different type of collection. You probably want to add the Text property of an existing TextBox control, not the string literal(with quotes) "textBox3.Text".

Data_Array.Add("Name", textBox3.Text); // Alex
Data_Array.Add("Year", textBox4.Text); // 1988



TextBox3 TextBox4 也是新名字不错的人选。

TextBox3 and TextBox4 are also good candidates for new names.

这篇关于如何让这阵+功能正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆