Home > Net >  C # array problem
C # array problem

Time:09-15

A button control, click once, and how to insert a string array, click it again and again in the array,
Don't know that array can't operation, can't get online

CodePudding user response:

List, also can understand into a dynamic array length,

 List List=new List (a); 
List. The Add (" dbconnect ");

CodePudding user response:

Understand first what is the Array, and then discuss how to operate, the Array can't be "insert" action, but can be reconstructed Array, surface such as insert, actual it is another operation, the reference Array. Copy,

CodePudding user response:

Array is not support insert, because arrays are in structure was applied to fixed size of memory, if you need to insert, you need to list data structures, such as the data structure can be when inserting data real-time application memory operations, the implementation of.net can use List To store, T here is a string type.

CodePudding user response:


Public static List List=new List (a);

This is the way you button click event public ()
{
Var listnew=list. Add (textbox. Text. The trim ());//this is a text box you name textbox listnew this is added to after you click on the value of the
}

CodePudding user response:

This use
List Rather than string [] better, list to support the add (string), directly inserted

CodePudding user response:

Array operation is relatively simple: at the end to add, in situ changes, insert a data item is very complicated to operate, need to put the insert position behind the data one by one back a place (starting from the data end operations), after waiting for the position vacant before writing new data, and then finished, to insert the length of the data may impact is not big, most systems should be able to handle,

CodePudding user response:

In the list
  •  Tags:  
  • C#
  • Related