簡體   English   中英

C#文本從文本框到字符串數組

[英]C# text from textbox to string array

我想通過按button3將文本從文本框添加到string []數組,我的值將添加到新數組並清除文本框。

Button1用於上升陣列,而Button2用於下降陣列。

我做這個,但它行不通:

namespace Test
{
    public partial class Form1 : Form
    {
        public int arr1 = 0;
        public int arr2 = 0;
        public string[] array = new string[100];

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (arr1 < array.Length - 1)
            {
                if (array[arr1] != "")
                {
                    arr1++;
                    textBox1.Text = array[arr1];
                }
            }
            else
            {
                arr1 = 0;
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            if (arr1 < array.Length - 1)
            {
                if (array[arr1] != "")
                {
                    arr1--;
                    textBox1.Text = array[arr1];
                }
            }
            else
            {
                arr1 = 0;
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            array[arr1] = textBox1.Text;
            listBox1.Items.Add(array[arr1]);
            arr2++;
            textBox1.Text = "";
        }
    }
}

有人可以幫我弄這個嗎? 謝謝

如下將arr2++替換為arr1++

private void button3_Click(object sender, EventArgs e)
    {
        array[arr1] = textBox1.Text;
        listBox1.Items.Add(array[arr1]);
        arr1++;
        textBox1.Text = "";
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM