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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Sep 21, 2012, 3:06 AM EDT
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?
Nitin BhardwajRank #139 · 16.1K reputationPosted Sep 21, 2012, 3:17 AM EDT
VulpesRank #55 · 29.2K reputationPosted Sep 21, 2012, 3:31 AM EDT
http://www.c-sharpcorner.com/Forums/Thread/180985/delegate-in-C-Sharp.aspx
Nitin BhardwajRank #139 · 16.1K reputationPosted Sep 21, 2012, 4:37 AM EDT
VulpesRank #55 · 29.2K reputationPosted Sep 21, 2012, 5:18 AM EDT
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: