I’m been wanting to create a user control, but before I do I need to know how to do a few things or even if its possible. I know it possible to pass a method to a function (Link). Is it possible to set a variable that is of function type? For example I have a user control where in one function I need to call GetData function. Each GetData routine is different so I was wondering if its possible to pass that function in from the aspx.cs page?
Share
The .NET Framework Library defines handy generic delegates (or “function types” as you call it). Function delegates that have a return value
Function delegates that have no return value
You can define a method that accepts a delegate like this
You can call it by either passing it an appropriate method or with a lambda expression.
Using this declaration
You can do the call (note that the parentheses () are missing after
Squaresince we do not want to call this method here)You get the same result with a lambda expression