I make a button that create a new form and pass to it an array but there is an error there is the code

int [] x=new int[9];
x={0,1,2,3,4,5,6,7,8};
form1 x =new form1(x);

and the other form constructor code is

public form1(int[]x)
        {
           InitializeComponent();
        }

Recommended Answers

All 3 Replies

What is the error?

paramerter int[]x is less accessible

The visual studio designer reflects controls with the parameterless constructor to render the control in the IDE. You should always chain your constructors and have a public parameterless constructor which will render a valid control.

For your form:

public partial class Form1 : Form
  {
    private int[] _array;

    public Form1()
    {
      InitializeComponent();
    }
    public Form1(int[] arr)
      : this()
    {
      this._array = arr;
    }

For your button:

private void button1_Click(object sender, EventArgs e)
    {
      int[] intArray = new int[] { 1, 2, 3, 4 };
      using (Form1 frm = new Form1(intArray))
      {
        frm.ShowDialog();
      }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.