Hi,
can we create delegate of constructor?
Please give me a example.
Loading
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 Sep 21, 2012, 7:06 AM
You can do it indirectly by wrapping a constructor call in a lambda expression like this:
but there doesn't seem much point.
What are you trying to do exactly?
VulpesPosted Sep 21, 2012, 9:18 AM
First we define a delegate type, MyDelegate, which takes an int parameter but doesn't have a return value. This means that the delegate is compatible with both the Treble and Square methods.
We then create a variable 'del' of the delegate type to which we can assign compatible methods.
Initially, we just call the Treble method with an argument of 10 by invoking the delegate.
However, we then add the Square method to the delegate (making it 'multicast') and invoke both methods with an argument of 20:
The output should be:
Nitin BhardwajPosted Sep 21, 2012, 8:37 AM
VulpesPosted Sep 21, 2012, 7:31 AM
http://www.c-sharpcorner.com/Forums/Thread/180985/delegate-in-C-Sharp.aspx
Nitin BhardwajPosted Sep 21, 2012, 7:17 AM