borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (tell me about static constructor)Next Topic (Login) New Topic New Poll Post Reply
AndreaVB Forum : ASP.Net : tell me about private constructor
Poster Message
tri_inn
Level: Regular User
Registered: 26-08-2002
Posts: 395

icon tell me about private constructor

if some one declare private constructor then how to create the instance of that class and what will be the advantage or disadvantage.
when some one will declare static constructor.

09-07-2004 at 06:28 AM
View Profile Send Email to User Show All Posts | Quote Reply
fabulous
Level: VB Guru


Registered: 03-08-2002
Posts: 439
icon Re: tell me about private constructor

If you get an error telling you that you cannot access a constructor because it is private you cannot make an instance of that class.

You will find that it won't make sense to create an instance of particular classes for your own purposes. Such classes are designed that way to avoid invalid use and in most cases are meant to be accesible as properties of other classes and serve no real purpose on their own.

If you find you cannot create an instance of a class then you will also find that you can get a reference to an instance of this class via a method or property. There is no way to access this constructor at all except from within the class itself if you are the author of the class.

Happy coding.  

____________________________
My boss is a Jewish Carpenter (Jesus Christ)


Brain Bench Certified VB.NET Developer

12-07-2004 at 04:57 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
zimcoder
Level: VB Lord


Registered: 27-10-2003
Posts: 225
icon Re: tell me about private constructor

It is very uncommon that one would want to create a class and then make its constructor private. this means that objects cannot be created from the class defined. Perhaps when this is used is with special purpose classes in which the internal working of the class may not be tempered with. Here you would most probably want certain members of your class to be initialised whenever a reference to methods of the class is made.

This works with static member functions and the contsructor will therefore be used to initialise data members or properties that the static method uses. Thats about the advantadge i can think of.


____________________________
BrainBench ADO.NET and ASP.NET Certified Developer

24-07-2004 at 05:58 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : ASP.Net : tell me about private constructor
Previous Topic (tell me about static constructor)Next Topic (Login) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder