需要将此C#程序添加到数组并从数组中删除任何想法 [英] need this C# program to be added to array and removed from array any ideas

查看:87
本文介绍了需要将此C#程序添加到数组并从数组中删除任何想法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string firstname;
      string lastname;
      string street;
      string city;
      string state;
      string zip;



      private void Form1_Load(object sender, EventArgs e)
      {
             string[] fullname;
      }

     // get info from textboxes
      private void btnAdd_Click(object sender, EventArgs e)
      {


// input of information to show in listbox

          if (firstnametxt.Text == "")

          {
          }
            else  MessageBox.Show("You must enter a First name.", "Name Entry Error",
                 MessageBoxButtons.OK, MessageBoxIcon.Exclamation);


              if (lastnametxt.Text == "")
              {
                  MessageBox.Show("You must enter a Last name.", "Name Entry Error",
                     MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
              }
              else


                  if (streettxt.Text == "")
                  {
                      MessageBox.Show("You must enter a Street adress .", "Adress Entry Error",
                         MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                  }
                  else
                            if (citytxt.Text == "")
                      {
                          MessageBox.Show("You must enter a City name.", "City Entry Error",
                             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                      }
                      else

                          if (statetxt.Text == "")
                          {
                              MessageBox.Show("You must enter a State.", "State Entry Error",
                                 MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                          }
                          else
                          {
                          }
                      }
                  }
              }



      private void btnDelete_Click(object sender, EventArgs e)
      {
          firstnametxt.Text = ("");
          lastnametxt.Text = ("");
          streettxt.Text = ("");
          citytxt.Text = ("");
          statetxt.Text = ("");
          ziptxt.Text = ("");
      }

      private void btnExit_Click(object sender, EventArgs e)
      {
          this.Close();
      }


      }

推荐答案

您不需要数组,需要使用输入值设置字段.尝试定义一个称为ValidateData的新方法.此方法仅负责数据验证.在btnAdd_Click方法中执行以下操作:
You don''t need an array, you need to set the fields with the input values. Try to define a new method called ValidateData. This method is responsible only for data validation. In btnAdd_Click method do this:
if (ValidateData())
{
     this.firstname = firstnametxt.Text;
     this.lastname = lastnametxt.Text;
     // continue setting field values
     this.DialogResult = DialogResult.OK;
}



另一个重要的事情是,您应该在此类中定义所有这些字段,应该创建一个新类,将其命名为Person,定义一个Person类型的字段并填充用户输入.毕竟,此表单类应返回一个Person.
我建议您阅读Apress的Pro C#之类的C#书籍.



Another important thing is that you should define all this fields in this class, you should create a new class, let''s name it Person, define a field of type Person and fill with user input. After all, this form class should return a Person.
I recommend you to read a C# book like Pro C# from Apress.


这篇关于需要将此C#程序添加到数组并从数组中删除任何想法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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