user3346282
user3346282

Reputation: 53

DataTable vs Array performance in c#

I am querying data from Database table say(ABCD) and want to store it in some DataStructure, then read it row by row and perform calculations on the values and update the datastructure with the modified values.

Finally once calculation on all the rows is finished, i would update ABCD table with updated values for each row.

Please suggest the data structure to be used which would give best performance. I am considering the use of 2D array or DataTable.

Upvotes: 2

Views: 4685

Answers (2)

Kusal Dissanayake
Kusal Dissanayake

Reputation: 752

Array

  1. The fastest data structure to read from is an array.
  2. Searching takes time
  3. Very inefficient to insert or remove something from an array

DataTables

  1. Faster searches (DataTable to LINQ is the fastest than DataTable.Select) LINQ was still a lot faster than using normal DataSet methods (40-50 times faster!)

  2. Fast insertions, removal, and sorting

Upvotes: 1

Eminem
Eminem

Reputation: 7484

An array is much lighter than a datatable but has no data structure operations. However while the data table is a heavy object it is much easier to work with

Upvotes: 5

Related Questions