首页 > 解决方案 > 我可以比较数组项吗?下面的代码和解释

问题描述

初学者程序员在这里,我正在尝试制作涂鸦。涂鸦是多人给出日期的地方,我的程序应该比较日期并显示所有三个人输入的日期中的哪一个是相同的。

namespace doodle_pittem
{
    public partial class Form1 : Form
    {
        int teller1,teller2,teller3;
        string[] Persoon1 = new string[5];
        string[] Persoon2 = new string[5];
        string[] Persoon3 = new string[5];

        public Form1()
        {
            InitializeComponent();
        }

        private void TxtPersoon1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == Convert.ToChar(Keys.Enter))
            {
                Persoon1[teller1] = TxtPersoon1.Text;
                TxtPersoon1.Text = "";
                teller1++;
                if (teller1==5)
                {
                    TxtPersoon2.Focus();
                    TxtPersoon1.Enabled = false;
                }
            }
        }

        private void TxtPersoon2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == Convert.ToChar(Keys.Enter))
            {
                Persoon2[teller2] = TxtPersoon2.Text;
                TxtPersoon2.Text = "";
                teller2++;
                if (teller2 == 5)
                {
                    TxtPersoon3.Focus();
                    TxtPersoon2.Enabled = false;
                }
            }
        }

        private void TxtPersoon3_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == Convert.ToChar(Keys.Enter))
            {
                Persoon3[teller3] = TxtPersoon3.Text;
                TxtPersoon3.Text = "";
                teller3++;
                if (teller3 == 5)
                {
                    TxtPersoon3.Enabled = false;
                    BerekenDatum();
                }
            }
        }
        private void BerekenDatum() 
        {
            string[] finaldatum = new string[15];
            for (int i = 0; i < 1; i++)
            {
                foreach (string datum1 in Persoon1)
                {
                    foreach (string datum2 in Persoon2)
                    {
                        foreach (string datum3 in Persoon3)
                        {
                            if (datum1 == datum2)
                            {
                                if (datum2 == datum3)
                                {
                                    finaldatum[i] = datum1;

                                }
                            }
                        }
                    }
                }
            }
      }
 }

对于草率的代码或奇怪的变量名感到抱歉,但它们是荷兰语,因为这是我的主要语言。任何帮助或提示将不胜感激

标签: c#

解决方案


推荐阅读