Today to share with you, how DataTable into List and Array, do this small U also spent a lot of time to study, and eventually found not so complicated.
First is that the difference between Array and List of:
List: just like a chain, space for storing data can not be continuous.
Array: Like a Execl in a column, but it would have to specify the size of the storage space at the time of the statement, in other words for words when the need is to declare the size of initialized data.
When will it use Array, List when to use it?
Summary 1: When we are not sure the size, it is best to use instead of Array List
Summary 2: When you need to find a large number of operations, it is best to use Array, with who knows who.
Summary 3: When the need for frequent insertions, deletions, it is best to use instead of Array List
Finally: As List need to store the address of his next node, so more space is wasted
The following small U will explain to you how to convert, in this case Activity in use are:
- Execl Application Scope
- Read Range
- Output Data Table
- Write Line
- Log Message
- For Each Row
- Invoke Method --- used to convert List
- For Each
- Use --- into an array Assign
The whole process looks very long, the actual principle is very simple, please be patient and read the small partner
(A) We take a look at how to output DataTable, this is actually very simple, direct a new OutputDataTable of activity on it
Since my form there is no header row, so to get rid of the title
See, that is so simple, just remember that he is the contents inside the entire DataTable as a string output.
(B) how to convert DataTable to List it?
Started this problem has been not know, always thinking with ForEachRow read, then direct assignment, how the results will not work, but fortunately found a way can be achieved by Invoke Method in the Add, pay attention to the type definition List is List <String> and the need for handling new List (of string) in the Default
---------------------------update content--------------------- --------
When using Invoke Method, we need to set the parameters, as shown below
Parameter Description missing, many students are stuck here today into this additional
Printing is very simple, direct use of ForEach, note that not ForEachRow
(C) how to convert List to an array, this is also very simple
This is just one step, array of type String []
Finally, we look at the output