Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8404539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:37:29+00:00 2026-06-09T22:37:29+00:00

Is it okay to place view = new Person within the button event handler?

  • 0

Is it okay to place "view = new Person" within the button event handler? If I don’t, and I place it within the Form1 constructor, only my last value gets added. Is that the proper way if I want to declare a new instance and then add it to my Arraylist?

    private ArrayList store;

    public Form1()
    {
        InitializeComponent();
        store = new ArrayList();
    }

    private void Form1_Load(object sender, EventArgs e)
    { }

    private void button1_Click(object sender, EventArgs e)
    {
        //Is it okay to declare a new instance of the Person class 
        // with each button push?            
        Person view = new Person();
        view.firstname = txtFirstName.Text;
        view.lastname = txtLastName.Text;
        store.Add(view);
        txtFirstName.Clear();
        txtLastName.Clear();   
    }

    private void button2_Click(object sender, EventArgs e)
    {
        foreach (Person display in store)
        {
            MessageBox.Show(display.ToString());
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:37:31+00:00Added an answer on June 9, 2026 at 10:37 pm

    Is it okay to place “view = new Person” within the button event handler?

    Yes. If your goal is to make a new person each time you click the button, this is appropriate to do.

    On a side note: You should consider using List<Person> instead of ArrayList. This is the newer, type-safe list class (as of .NET 2.0), and far nicer to use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it okay to place an oracle driver jar within the web application's /lib
(Not sure if this is an okay place to ask, but i'll try). After
Assuming indexes are put in place, and absolute-count-accuracy is not necessary (it's okay to
Okay look first thanks for this place :) I would like to create a
Okay, so not sure if apple.stackexchange is a better place for this, but I
Okay, i'm very new to Javascript and i'm trying to create a slideshow with
Okay really weird situation with AdMob. I want to place the ad on the
Okay, this all takes place in a nice and simple 2D world... :) Suppose
Okay, I understand how to work delegation in a modal view to send a
Okay. So at my place of work there is a products table in our

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.