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.CreateIns tance(DataType, Size)
End Sub
Public Function Max() As Double
' find maximum value of the area
Dim sortedData As Array
sortedData = Array.CreateIns tance(GetType(D ouble),
Data.GetUpperBo und(0) + 1)
Data.CopyTo(sor tedData, 0)
Array.Sort(sort edData)
Return sortedData(sort edData.GetUpper Bound(0))
End Function
End Class 2 1323
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******** ********@TK2MSF TNGP15.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.CreateIns tance(DataType, Size) End Sub
Public Function Max() As Double ' find maximum value of the area Dim sortedData As Array sortedData = Array.CreateIns tance(GetType(D ouble), Data.GetUpperBo und(0) + 1) Data.CopyTo(sor tedData, 0) Array.Sort(sort edData) Return sortedData(sort edData.GetUpper Bound(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******** ********@TK2MSF TNGP15.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.CreateIns tance(DataType, Size) End Sub
Public Function Max() As Double ' find maximum value of the area Dim sortedData As Array sortedData = Array.CreateIns tance(GetType(D ouble), Data.GetUpperBo und(0) + 1) Data.CopyTo(sor tedData, 0) Array.Sort(sort edData) Return sortedData(sort edData.GetUpper Bound(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 any preconceived ideas about it. I have
noticed, however, that every programmer I talk to who's aware of Python is
also talking about Ruby. So it seems that Ruby has the potential to compete
with and displace Python. I'm curious on what basis it...
|
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.
Two sub-classes have the relationship to communicate back and forth
through this pointer. The pointer is responsible inside Top class for
allocating and deallocating two sub-classes.
CMemory class is responsible to allocate and deallocate memory...
|
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, I've
been playing with Qt in KDE on a Slackware 10.0 system, and following
their cookbook exercises, and everything's working, and I have no
clue what the code is doing, i.e.. how do I connect my brain to the
ascii in the files to the stuff on...
|
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 follow for
creating a program?
I am writing a map game program. I created several objects: board
object that is an array of integers each number 0-5 is a kind of
terrain, a terrain object that is an array of terrain types and each
number of...
|
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
interfaces.
Like anything else, it appears Interfaces are by design something that
requires documentation. I know this may be obvious, but if I have a
class A and I say, well, class A implements IMyInterface. The fact
that it implements...
|
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 it's late and my brain is frazzled. Any ideas, oh PHP gurus?
--
|
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 like 65% of
the time of the second routine. Yet both do the same thing. However,
the second one seems better in terms of the way the code is written
since it helps encapsulate the transformation in the inner loop better
making it easier to read,...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |