Passing array between forms and managing in arrays

后端 未结 4 1047
走了就别回头了
走了就别回头了 2020-12-20 03:46

I want to transfer an array from Form1 to Form2, then on Form2 add some values to the array. On Form1 button click I put this code:

        int[] arrayOfInt          


        
4条回答
  •  感动是毒
    2020-12-20 04:25

    Use List and use oList.Add(item) method to add elements as array is Fixed in Lenght (you already giving it size at a time of initialization) But if you want to use array at any cost then make a logic to create a new array upto the size of Old+ new added element and return that.

    UPDATED I believe you are facing problem because you have taken List of String instead or Int.

                List oIntList = new List();
                oIntList.Add(1);
                oIntList.Add(3);
                oIntList.Add(4);
                oIntList.Add(5);
    
                int[] oIntArr = oIntList.ToArray();
    

提交回复
热议问题