---
title: "Pass array from form load to button click"  
description: "Pass array from form load to button click"  
author: "Anonymous User"  
published: 2014-11-14  
updated: 2014-11-15  
canonical: https://www.mindstick.com/forum/12588/pass-array-from-form-load-to-button-click  
category: "c#"  
tags: [".net"]  
reading_time: 2 minutes  

---

# Pass array from form load to button click

New C# user. I understand [global](https://www.mindstick.com/articles/13127/macro-and-microeconomics-concepts-in-relation-to-global-organization-management) [variables](https://www.mindstick.com/articles/715/php-variables) are not part of C#. Been [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) [learning](https://www.mindstick.com/articles/126221/instructional-design-for-elearning-why-it-is-so-important) [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties), set and get. But I have what must be a [common](https://www.mindstick.com/articles/23170/10-most-common-accounting-mistakes-of-small-business) situation and I can't find the answer. This is what normally seems to happen when I [design](https://www.mindstick.com/articles/12279/interior-design-and-furniture-store-wordpress-theme) a form:

```
private void Form1_Load(object sender, EventArgs e) {              private void Form1_Load(object
sender, EventArgs e)        {         Label[]  labelsArray = { label1, label2, label3,
label4, label5 };        }    private void
button1_Click(object sender, EventArgs e)        {            ...        }}
```

So I made a "labelsArray" in Form1_Load that I want to use in the button1_Click. But I cannot - "Error 1 The name 'labelsArray' does not exist in the current [context](https://www.mindstick.com/forum/23245/what-is-context-in-android)".

I do have [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) to the [labels](https://www.mindstick.com/forum/34568/badges-labels-page-headers) in button1_Click and I suppose I can re-declare the array and it'd work. But seems like I should be able to pass the array from Form1_Load to button1_Click and use it. But I'm lost after trying many things. How is it done please?

## Replies

### Reply by Mark M

All you need to do is to declare the variable outside the methods like:

```
private Label[] 
labelsArray = null;private void Form1_Load(object sender, EventArgs e){   labelsArray = new Label[]{
label1, label2, label3, label4, label5 };}private void button1_Click(object sender, EventArgs e){}
```


---

Original Source: https://www.mindstick.com/forum/12588/pass-array-from-form-load-to-button-click

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
