thanks for the help...just one more question....
can a class have more then two parameterized constructors?.. i would like to
be able to instanciate the class with a different number of argument.....
thanks folks
steve 6 2391
Stephen,
Constructors can be overloaded just like other methods, as long as the
parameter types are different.
Public Class SomeClass
Public Sub New()
End Sub
Public Sub New(ByVal i As Integer)
End Sub
Public Sub New(ByVal s As String)
End Sub
Public Sub New(ByVal ParamArray args() As String)
End Sub
End Class
You can even include optional parameters, however I normally favor
overloading to the Optional keyword.
As I stated in my other post, overloading constructors, base classes & other
OOP concepts are explained in Robin A. Reynolds-Haertle's book "OOP with
Microsoft Visual Basic .NET and
Microsoft Visual C# .NET - Step by Step" from MS Press covers this plus the
rest of OOP in VB.NET, in a very straight forward manner.
OOP concepts in VB.NET is also covered in this section of MSDN. http://msdn.microsoft.com/library/de...ithObjects.asp
Of course you are welcome to ask in the newsgroups also.
Hope this helps
Jay
"Stephen Martinelli" <st*****@johnst ontrading.com> wrote in message
news:eP******** ******@TK2MSFTN GP09.phx.gbl... thanks for the help...just one more question....
can a class have more then two parameterized constructors?.. i would like
to be able to instanciate the class with a different number of argument.....
thanks folks
steve
Hi Stephen,
You can have as many as you like so long as they are distinct.
These two are the same, despite having different variables
Sub New (Foo As Integer, sSomething As String)
Sub New (Bar As Integer, sDifferent As String)
This is because the <signature> is the same - ie. they both have the same
parameter types. Sub New (Integer, String)
Methods which have the same name but different parameter types
(signatures) are called 'overloads'. Overloading is very handy - as you're
discovering. ;-)
Regards,
Fergus
On 2003-10-23, Jay B. Harlow [MVP - Outlook] <Ja********@ema il.msn.com> wrote: Stephen, Constructors can be overloaded just like other methods, as long as the parameter types are different.
Public Class SomeClass
Public Sub New() End Sub
Public Sub New(ByVal i As Integer) End Sub
Public Sub New(ByVal s As String) End Sub
Public Sub New(ByVal ParamArray args() As String) End Sub
End Class
You can even include optional parameters, however I normally favor overloading to the Optional keyword.
Me too. Probably because I code mostly in C#, and C# doesn't support
optional paramters. Also, Optional can cause problems latter on since
the default values actually get compiled into the code and become part
of the interface. If you latter need to change the default it has the
potential to lead to incompatabiliti es between versions.
--
Tom Shelton
MVP [Visual Basic]
I've found though, that constructors are special and don't work the same as
other overloaded members. If you overload a constructor like this:
Public Class A
Public Sub New()
End Sub
Public Sub New(x as string)
End Sub
Public Sub new(y as integer)
End Sub
End Class
And then you make a new class (B) that inherits from "A", the overloaded
constructors won't be available. This is only the case with constructors,
do this overloading with any other class member and the overloaded versions
are available in the derived classes.
"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message
news:eC******** ******@TK2MSFTN GP12.phx.gbl... Stephen, Constructors can be overloaded just like other methods, as long as the parameter types are different.
Public Class SomeClass
Public Sub New() End Sub
Public Sub New(ByVal i As Integer) End Sub
Public Sub New(ByVal s As String) End Sub
Public Sub New(ByVal ParamArray args() As String) End Sub
End Class
You can even include optional parameters, however I normally favor overloading to the Optional keyword.
As I stated in my other post, overloading constructors, base classes &
other OOP concepts are explained in Robin A. Reynolds-Haertle's book "OOP with Microsoft Visual Basic .NET and Microsoft Visual C# .NET - Step by Step" from MS Press covers this plus
the rest of OOP in VB.NET, in a very straight forward manner.
OOP concepts in VB.NET is also covered in this section of MSDN. http://msdn.microsoft.com/library/de...ithObjects.asp Of course you are welcome to ask in the newsgroups also.
Hope this helps Jay
"Stephen Martinelli" <st*****@johnst ontrading.com> wrote in message news:eP******** ******@TK2MSFTN GP09.phx.gbl... thanks for the help...just one more question....
can a class have more then two parameterized constructors?.. i would like to be able to instanciate the class with a different number of
argument..... thanks folks
steve
* "Scott M." <s-***@badspamsnet .net> scripsit: I've found though, that constructors are special and don't work the same as other overloaded members. If you overload a constructor like this:
Public Class A Public Sub New() End Sub
Public Sub New(x as string) End Sub
Public Sub new(y as integer) End Sub End Class
And then you make a new class (B) that inherits from "A", the overloaded constructors won't be available. This is only the case with constructors, do this overloading with any other class member and the overloaded versions are available in the derived classes.
ACK. Constructors are not inherited from the base class.
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Scott,
Of course, as Herfried pointed out constructors are NEVER inherited, it does
not make sense to inherit a constructor, as each class requires its own
constructor.
If you do not give a class a constructor one will be provided for you,
provided that your base class has a default constructor. The constructor
provided for you is called the default constructor and has no parameters.
If you provide your class with any constructors, the default constructor
will not be provided for you. In this case if you need a parameterless
constructor you need to provide it yourself.
Again each class requires its own constructor, except in the case of
providing a default (parameterless constructor) the compiler cannot and
should not attempt to decide what a constructor should look like, as the
designer of the class knows best what constructors the class needs!
This is all covered in the link I gave.
Thanks for the catch.
Jay
"Scott M." <s-***@badspamsnet .net> wrote in message
news:uw******** ******@TK2MSFTN GP09.phx.gbl... I've found though, that constructors are special and don't work the same
as other overloaded members. If you overload a constructor like this:
Public Class A Public Sub New() End Sub
Public Sub New(x as string) End Sub
Public Sub new(y as integer) End Sub End Class
And then you make a new class (B) that inherits from "A", the overloaded constructors won't be available. This is only the case with constructors, do this overloading with any other class member and the overloaded
versions are available in the derived classes. "Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in
message news:eC******** ******@TK2MSFTN GP12.phx.gbl... Stephen, Constructors can be overloaded just like other methods, as long as the parameter types are different.
Public Class SomeClass
Public Sub New() End Sub
Public Sub New(ByVal i As Integer) End Sub
Public Sub New(ByVal s As String) End Sub
Public Sub New(ByVal ParamArray args() As String) End Sub
End Class
You can even include optional parameters, however I normally favor overloading to the Optional keyword.
As I stated in my other post, overloading constructors, base classes & other OOP concepts are explained in Robin A. Reynolds-Haertle's book "OOP with Microsoft Visual Basic .NET and Microsoft Visual C# .NET - Step by Step" from MS Press covers this plus the rest of OOP in VB.NET, in a very straight forward manner.
OOP concepts in VB.NET is also covered in this section of MSDN. http://msdn.microsoft.com/library/de...ithObjects.asp Of course you are welcome to ask in the newsgroups also.
Hope this helps Jay
"Stephen Martinelli" <st*****@johnst ontrading.com> wrote in message news:eP******** ******@TK2MSFTN GP09.phx.gbl... thanks for the help...just one more question....
can a class have more then two parameterized constructors?.. i would
like to be able to instanciate the class with a different number of argument..... thanks folks
steve
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rajesh Garg |
last post by:
Can we have private constructors and destructors? IF yes what is the
use of such constructors or destructors.....in the sense where can
these be implemented in a system.................
I have an idea that we can have private constructors and destructors
but am not able to find a situation where they can be used...
Regards
RVG
rajeshgarg@opussoft.com
|
by: Edward Diener |
last post by:
Coming from the C++ world I can not understand the reason why copy
constructors are not used in the .NET framework. A copy constructor creates
an object from a copy of another object of the same kind. It sounds simple
but evidently .NET has difficulty with this concept for some reason. I do
understand that .NET objects are created on the GC heap but that doesn't
mean that they couldn't be copied from another object of the same kind when...
|
by: Sathyaish |
last post by:
What is a private constructor, and why would a class have one? What are
the other kinds of constructors besides:
(1) public constructors; and
(2) parameterized constructors
And I understand that they are not mutually exclusive of one another.
The above classification assimilates my knowledge of having used
constructors in both the above manners.
|
by: John |
last post by:
Trying to find out what is essential / optional, I made an extremely simple
Class and Module combination to add two numbers. (see below)
It appears that an empty constructor is needed n order to work right,
although I quite don't see what is does in addition to the 2nd constructor.
Also, the example works fine without message calls in either constructor
(the numerical answer is still there and correct!).
I exected it to no longer work...
|
by: John |
last post by:
Before anything else, thanks Marina, Workgroups and Ralf, for your help so far.
I am now able to better define the question!
After adding more console printout lines to CSum, I tried all permutations
for constructors (none, default, two argument) and method call in body of
constructor (none and one).
Maybe this example is not representative, but for this example I found the
following:
1. Without any constructors, the program works fine...
| |
by: Peter Morris [Droopy eyes software] |
last post by:
Look at these two classes
public class Test
{
public readonly string Name;
public Test(string name)
|
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: 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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: 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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
| |
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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
| |