Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# callback action lambda

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

public class CallbackUsingActionAndLambdaDemo : MonoBehaviour {

	void Start(){
		DoWork ((String result) => Debug.Log (result)); //passing the executable code to DoWork() as a callback (after doing work in DoWork(), the code which has been sent will be executed)
	}

	public void DoWork(Action<string> callback){
		bool isWorkDone;

		//do work here
		isWorkDone = true;

		if (isWorkDone)
			callback ("yes work is done successfully");
		else
			callback ("sorry work is not done");

	}
}
 
PREVIOUS NEXT
Tagged: #callback #action #lambda
ADD COMMENT
Topic
Name
7+4 =