c# - Passing a method with parameter Func and getting TResult -
So basically there is a return type in T, I want to return the generic return type. Example: How do I just call T and get a trashlech? I remember, I only have t. Edit: How do I tell this method? Edit: I want a general interconnection, because I'm trying a lot on different endvoks, then I want results from endwoke. I first of all used my generic This method will make calls easier. For example, I Call a method that calculates the square of an integer. In your client code, you call it this like this: Edit This example has not been tested in any way, and there is a clear race condition in it. Private trace endwolf & lt; T, TResult & gt; (Funk & lt; T, TResult & gt; asyncCaller, IAsyncResult asyncResult) {Trust Result = Default (TResult); Try {result = asyncCaller.EndInvoke (asyncResult); } Hold (exception exception) {// get exception details} return result; }
endInneq & lt ;, & gt; I suggest changing the method.
Public Stable Class FuncExtensions {Public Static Trashlutt and Invoke & lt; T, TResult & gt; (This fax & lt; T, TResult & gt; asyncCaller, IAsyncResult asyncResult) {// ...}}
Private integer square (int x) {return x * x; }
F & lt; Int, int & gt; Caller = new funk & lt; Int, int & gt; (Square); Int x = 5; Int y = default (int); Caller.BeginInvoke (x, asyncResult = & gt; {y = caller.EndInvoke (asyncResult);}, tap); Console.light line ("{0} is square {1}", x, y);
Comments
Post a Comment