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 2 1297
In Visual Studio 2005 you will be able to use generics to create a template
for a class or method where you can pass a type as an argument to the
class/method at runtime.
For now, you can emulate this future behavior to some extent by adding
overloaded methods to the class you have started.
--
Mike
Mike McIntyre
Visual Basic MVP www.getdotnetcode.com
"Dave" <dave@4_rem_ove_scotts.com> wrote in message
news:e8****************@TK2MSFTNGP15.phx.gbl... 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
In Visual Studio 2005 you will be able to use generics to create a template
for a class or method where you can pass a type as an argument to the
class/method at runtime.
For now, you can emulate this future behavior to some extent by adding
overloaded methods to the class you have started.
--
Mike
Mike McIntyre
Visual Basic MVP www.getdotnetcode.com
"Dave" <dave@4_rem_ove_scotts.com> wrote in message
news:e8****************@TK2MSFTNGP15.phx.gbl... 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Brandon J. Van Every |
last post by:
What's better about Ruby than Python? I'm sure there's something. What is
it?
This is not a troll. I'm language shopping and I want people's answers. I
don't know beans about Ruby or have...
|
by: Bryan Parkoff |
last post by:
I have created three classes according to my own design. First class
is called CMain. It is the Top Class. Second class and third class are
called CMemory and CMPU. They are the sub-classes....
|
by: Gaurav |
last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250
Any comments?
Thanks
Gaurav
|
by: Rich Grise |
last post by:
I think I've finally found a tutorial that can get me started:
http://www.zib.de/Visual/people/mueller/Course/Tutorial/tutorial.html
and I've been lurking for awhile as well. What happened is,...
|
by: Richard Hengeveld |
last post by:
Hi all,
I'm trying to understand how pointers for function parameters work. As I
understand it, if you got a function like:
void f(int *i)
{
*i = 0;
}
|
by: JoeC |
last post by:
I am a self taught programmer and I have figured out most syntax but
desigining my programs is a challenge. I realize that there are many
ways to design a program but what are some good rules to...
|
by: jm |
last post by:
I am having trouble understanding the purposes of an interface, even
though the concept of interfaces is around me all the time (user
interface, for example). I'm just not understanding software...
|
by: Mary Pegg |
last post by:
There's got to be a better way:
if (isset($c)) echo $c."<br>";
if (isset($c)) echo $c."<br>";
if (isset($c)) echo $c."<br>";
if (isset($c)) echo $c."<br>";
if (isset($c)) echo $c."<br>";
but...
|
by: mike3 |
last post by:
Hi.
(Xposted to both comp.lang.c++ and comp.programming since I've got
questions related to both C++ language and general programming)
I've got the following C++ code. The first routine runs in...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |