static void Main(string[] args) { // Creating an anonymous method GetTextDelegate getTextDelegate = delegate(string name) { return("Hello, " + name); }; // Lambda expression GetTextDelegate getHelloText = (string name) => { return("Hello, " + name); }; // Statement lambda GetTextDelegate getGoodbyeText = (string name) => { Console.WriteLine("I'm inside of a lambda statement"); return("Goodbye, " + name); }; // even nicer lambda expression, also it only works because it's just one variable the "name" variable GetTextDelegate getWelcomeText = name => "Welcome, " + name; // lambda expression with various variables GetResultDelegate getSum = (a, b) => a + b; GetResultDelegate getProduct = (a, b) => a * b; DisplayNum(getSum); DisplayNum(getProduct); Console.WriteLine(getWelcomeText("Denis")); //Display(getTextDelegate); SayHello(); Console.ReadKey(); }
static void Main(string[] args) { GetTextDelegate getTextDelegate = delegate(string name) { return("Hello, " + name); }; //Lambda expression GetTextDelegate getHelloText = (string name) => { return("Hello, " + name); }; GetTextDelegate getGoodbyText = (string name) => { Console.WriteLine("I'm inside of an statement lambda"); return("Goodby, " + name); }; GetTextDelegate getWelcomeText = name => "Welecome " + name; GetResultDelegate getSum = (a, b) => a + b; GetResultDelegate getProduct = (a, b) => a * b; Display(getTextDelegate); DisplayNum(getSum); DisplayNum(getProduct); Console.WriteLine(getWelcomeText("Yuko")); }
static void Main(string[] args) { // Anonymous method, aka in-line delegate GetTextDelegate getTextDelegate = delegate(string name) { return("Hello from the GetTextDelegate made by " + name); }; // Expression Lambda GetTextDelegate getHelloText = (string name) => { return("Hello, " + name); }; // Statement Lambda GetTextDelegate getGoodbyeText = (string name) => { Console.WriteLine("I'm inside of a statement Lambda"); return("Goodbye, " + name); }; // Real used Lambda's, shortened Lambda GetTextDelegate getWelcomeText = name => "Welcome, to real Lambdas " + name; GetResultDelegate getSum = (a, b) => a + b; GetResultDelegate getProduct = (c, d) => c * d; DisplaySum(getSum); DisplaySum(getProduct); Console.WriteLine(getWelcomeText("Rob")); }
public MyGetNotFinishedSellStoneAsyncResult(HttpContext context, AsyncCallback callBack, GetResultDelegate action, object state) { this._context = context; this._asyncCallback = callBack; this._state = state; this._action = action; }
/// <summary> /// Use this function to enqueue a command with an expected return object of type T. /// The command will deserialize the respone as type T and pass it to the callback. /// /// </summary> /// <typeparam name="T"> Type of the expected return object</typeparam> /// <param name="uri">The URI of the waapi command</param> /// <param name="args">The command-specific arguments</param> /// <param name="options">The command-specific options</param> /// <param name="callback">Function accepting an argument of type T</param> public static void QueueCommandWithReturnType <T>(string uri, GetResultDelegate <T> callback, string args = null, string options = null) { waapiCommandQueue.Enqueue(new WaapiCommand( async() => { var result = await WaapiClient.Call(uri, args, options); callback(UnityEngine.JsonUtility.FromJson <T>(result)); })); }
static void Main(string[] args) { // Anonymous method / Inline Delegate GetTextDelegate getTextDelegate = delegate(string name) { return("Hello, " + name); }; Console.WriteLine(getTextDelegate("Philip")); // method compiles first SayHello(); // pass anonymous method Display(getTextDelegate); // Lambda expression GetTextDelegate getHelloText = (string name) => { return("Hello from LBD, " + name); }; Console.WriteLine(getHelloText("Gurender")); // Statement Lambda GetTextDelegate getGoodbyeText = (string name) => { Console.WriteLine("I'm inside of a statement Lambda"); return("Goodbye, " + name); }; Console.WriteLine(getGoodbyeText("Philip")); GetTextDelegate getWelcomeText = name => "Welcome, " + name; Console.WriteLine(getWelcomeText("Gurender")); GetResultDelegate addNumbers = (a, b) => a + b; Console.WriteLine("Addition of 5 and 17 is: " + addNumbers(5, 17)); GetResultDelegate multiplyNumbers = (a, b) => a * b; Console.WriteLine("Multiplication of 5 and 7 is: " + multiplyNumbers(5, 7)); //using function DisplayNum(addNumbers); DisplayNum(multiplyNumbers); }
public static void AnonymousMain(string[] args) { //Creating an anonymous method GetTextDelegate getTextDelegate = delegate(string abc) { return("Hello ," + abc); }; Console.WriteLine(getTextDelegate("Aman")); //Expression lambda GetTextDelegate getHello = (string name) => { return("Hello, " + name); }; Console.WriteLine(getHello("How are you")); //Statement lambda GetTextDelegate getGoodbyetext = (string name) => { Console.WriteLine("I'm inside of an statement"); return("Goodbye, " + name); }; Console.WriteLine(getGoodbyetext("Raj")); //Powerful lambda expression... GetTextDelegate getWelcomeText = name_ => "Welcome, " + name_; Console.WriteLine(getWelcomeText("New members")); GetResultDelegate getSum = (a, b) => a + b; DisplayNum(getSum); Display(getTextDelegate); Console.ReadKey(); }
static void DisplayNum(GetResultDelegate getResultDelegate) { Console.WriteLine(getResultDelegate(2.0, 5.0)); }
public void Do(GetResultDelegate getResult) { Console.WriteLine(getResult()); // 콜백 메서드 호출 }
static void DisplayNum(GetResultDelegate getResultDelegate) { Console.WriteLine(getResultDelegate(3.5, 2.5)); }
static void DisplaySum(GetResultDelegate getResultDelegate) { Console.WriteLine(getResultDelegate(6.6, 4.5)); }
public void Do(GetResultDelegate _delegate) { Console.WriteLine(_delegate); }