DataTable or Array

T

twq

Hello

I would like to populate a 2-dimensional array with different
datatyps , 1. dimension is always a String, 2. dimension could be of
Typ Double or String.

What would be the better solution performance wise, to create an
String Array and then try to Convert the 2. Dimension into either
double or String, or to create an Datatable with Double & String
Columns, or is there any other way to do it?

Thank you in advance
 
C

Cor Ligthert [MVP]

Hi,

Forget the performance or you should be interested in parts of picoseconds.

Take that which fits you the best and is the best maintanable afterwards.

Mostly I take direct a datatable, because with that I get a lot of extra
methods which I don't have at the array.

But feel free to do it in another way as you are more used with arrays.

Cor
 
T

twq

Follow up question,

How would you implement a Datatable as a Property of Class where the
Table would have 5 specified columns?

thanks
 
R

RobinS

Follow up question,

How would you implement a Datatable as a Property of Class where the
Table would have 5 specified columns?

thanks

You can just add it as a property, and then create it and/or populate it in
your constructor. Here's an example.


Public Class Car

Private _ColorTable As DataTable
Property ColorTable() As DataTable
Get
Return _ColorTable
End Get
Set(byVal value As ColorTable)
_ColorTable = value
End Set
End Property

Public Sub New()
CreateColorTable()
End Sub

Private Sub CreateColorTable()
'This creates a new datatable. You could just as
' easily read it in from a data source.
' I wasn't sure which method you were using.
Dim ct as New DataTable()
ct.Columns.Add("Red", GetType(Integer))
ct.Columns.Add("Blue", GetType(Integer))
ct.Columns.Add("Green", GetType(Integer))
ct.Columns.Add("Hue", GetType(Integer))
ct.Columns.Add("ColorName", GetType(String))
ColorTable = ct
End Sub

End Class


Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
 
D

dbahooker

use an array

ADO.net is about ready for another 'Visual Fred' moment and you don't
want to have to rewrite everything every 2 years
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top