D
Dave
I know in C++ you can create class templates so the data type can be defined
during the declaration of an instance of a class. I was trying to do
something like that for a VB.NET class cut am not really sure where to
start.
Here is an example for a simple DataArray class definition that sets up an
array used for numerical data and adds some additional functionality to the
array. The overloaded new methods work okay, although I'm not sure if it's
the right way to go about doing this, but for the other methods do I have to
write an overloaded method for each data type, or can I set these up to
identify the type of array that was created for this instance of the class?
Public Class DataArray
Public Data As Array
Public Sub New(ByVal dt As Array)
Data = dt
End Sub
Public Sub New(ByVal Size As Integer, ByVal DataType As Type)
Data = Array.CreateInstance(DataType, Size)
End Sub
Public Function Max() As Double
' find maximum value of the area
Dim sortedData As Array
sortedData = Array.CreateInstance(GetType(Double),
Data.GetUpperBound(0) + 1)
Data.CopyTo(sortedData, 0)
Array.Sort(sortedData)
Return sortedData(sortedData.GetUpperBound(0))
End Function
End Class
during the declaration of an instance of a class. I was trying to do
something like that for a VB.NET class cut am not really sure where to
start.
Here is an example for a simple DataArray class definition that sets up an
array used for numerical data and adds some additional functionality to the
array. The overloaded new methods work okay, although I'm not sure if it's
the right way to go about doing this, but for the other methods do I have to
write an overloaded method for each data type, or can I set these up to
identify the type of array that was created for this instance of the class?
Public Class DataArray
Public Data As Array
Public Sub New(ByVal dt As Array)
Data = dt
End Sub
Public Sub New(ByVal Size As Integer, ByVal DataType As Type)
Data = Array.CreateInstance(DataType, Size)
End Sub
Public Function Max() As Double
' find maximum value of the area
Dim sortedData As Array
sortedData = Array.CreateInstance(GetType(Double),
Data.GetUpperBound(0) + 1)
Data.CopyTo(sortedData, 0)
Array.Sort(sortedData)
Return sortedData(sortedData.GetUpperBound(0))
End Function
End Class