Well as everyone know constructor is must either implicit or explicit one :)
Well i hope there will be only single constructor static or non-static . is there any hope there will be 2 constructors in single class ? If so how it works
Thank you
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Mar 7, 2013, 6:37 AM
However, it can contain any number of instance constructors.
If you don't provide an instance constructor, then the system provides a default parameterless constructor which does nothing except call the base class's constructor.
Here's an example of a class which contains two instance constructors. Notice how the constructor which takes a single int parameter 'chains' to the other constructor (using the 'this' keyword) which takes int and string parameters, passing the latter a default value:
The output of this program is:
VulpesPosted Mar 8, 2013, 10:45 AM
// form 1
// form2
// any other code
When you click the button, the label on form2 should show the currently selected item in the combobox.
Moreover, if you subsequently change the selected item in the combobox on form1, the new item should show automatically in the label on form2.
SUNIL GUTTAPosted Mar 8, 2013, 5:31 AM
i tried like this . I got a doubt did i understood question right ?
I hope i understood question right i.e i used combobox1 & button1 on form 1 and when i click button1 the data selected in combobox1 should get in form2 component like label1 :)
Coming to your approach i tried can you please put me in programming style i can understand much better & debugg to know whats going on
TY
VulpesPosted Mar 7, 2013, 7:27 PM
SUNIL GUTTAPosted Mar 7, 2013, 10:52 AM
http://www.c-sharpcorner.com/Forums/Thread/201338/
can you explain me this in your simple way so i can understand your type of dealing .
Thank u for burden & i tried to go through ur explanation in that post but i'm confused
VulpesPosted Mar 7, 2013, 8:34 AM
Your own program, which doesn't use constructor chaining, is working fine. Notice that when you use the constructor which takes a single int argument, then 's' is set to its default value of null.
When you have something like this:
it executes as though it were written like this:
MyClass(i, "Hello);
though if you try to write it like that you'll get a compiler error.
So, one constructor is calling another which saves you having to copy the second constructor's code into the first. Hence the term : 'constructor chaining'.
If you're using C# 4.0 or later, you can also use a single constructor with an optional parameter to achieve the same result:
public MyClass(int i, string s = "Hello")
{
}
If someone calls this constructor with only a single int parameter, then the second parameter is given its default value of "Hello".
http://msdn.microsoft.com/en-us/library/vstudio/ms173115(v=vs.100).aspx
SUNIL GUTTAPosted Mar 7, 2013, 7:42 AM
Chains ?? i never used 'this' keyword at end of constructor like
public MyClass(int i) : this(i, "Hello")
can you plz explain it ?
Can you refer me any material or anything to find such different approaches .
SUNIL GUTTAPosted Mar 7, 2013, 7:39 AM
Ty for help
AM i right please do check below program .! do that justify my question ? i hope it does .! ur view plz