dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online Membersbaskar
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Forums » .NET » .NET »

Calling constructor from constructor


Posted Date: 11 Jul 2012      Posted By:: Saurabh Tyagi     Member Level: Silver    Member Rank: 1755     Points: 2   Responses: 3




i have a class with tree constructor, one default, second parametrized, third copy. i call only default constructor from code. now i want when i call default constructor other two also have to run.

class class1
{
class1(){}
class1(int a, int b) {}
class1(class1 ss) {}

}

///Regards,

Saurabh Tyagi




Responses

#679850    Author: Anil Kumar Pandey      Member Level: Platinum      Member Rank: 1     Date: 11/Jul/2012   Rating: 2 out of 52 out of 5     Points: 2

Constructors are called automatically you can not force the other when Default is called,

if you have to call the parametrized constructor you must pass the value while creating the object.


Class1 obj new class1(1,2);


Thanks & Regards
Anil Kumar Pandey
Microsoft MVP, DNS MVM



 
#679855    Author: SonyMadhu      Member Level: Gold      Member Rank: 45     Date: 11/Jul/2012   Rating: 2 out of 52 out of 5     Points: 2

Hi Surabh,



Yes, Constructor of a class called automatically when the Object is instantiated.
There are different constructors.
1.Default Constructor which is same as class name
2.Parameterized Constructor
3.Copy Constructor

Regards,
Madhu
Be so hapy wen others look at you,they become hapy too



 
#679881    Author: Kapil      Member Level: Gold      Member Rank: 51     Date: 11/Jul/2012   Rating: 2 out of 52 out of 5     Points: 2

Hi,

I am not sure why you want to do that way. You can instantiate the object of that class my passing correct parameters

If you want to call, you should have some functions with that functionality and call the function in default constructor.

Hope that will help...

Happy Coding

"Please don't forget to Rate this answer if you found it usefull"

http://www.dotnetspider.com/mentors/86-kapil-deo.aspx
My Blog






 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : How to create an App pool dynamically
Previous : To print the numbers using C# .net
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.