|
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:  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:  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:  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. |
|
|
|
|
 Follow us on Twitter: https://twitter.com/dotnetspider
|
|