Does anyone know how the source code is declared for the Func and Action pointers? I’m trying to understand the theory behind making an asynchronous call using delegates and how that is tied to threading.
For example, if I have the code below:
static void Main()
{
Func<string, int> method = Work;
IAsyncResult cookie = method.BeginInvoke ("test", null, null);
//
// ... here's where we can do other work in parallel...
//
int result = method.EndInvoke (cookie);
Console.WriteLine ("String length is: " + result);
}
static int Work (string s) { return s.Length; }
How would I use the ‘delegate’ type to replace the Func<> structure; the reason I’d like to figure it out is because Func can only take an input and a return variable. It doesn’t allow for design flexibility in the method that it’s pointing to.
Thanks!
Func<int, string>is just a generic delegate. It just helps you avoid writing common delegates. That’s it. If it doesn’t fit for you should write your own delagate.the delagate to replace the one you are asking is
if you want a func(for istance) that takes 22 🙂 integer and return a string you have to write you own delegate
In your case