Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

C# actions

//Action is a invokeable container for Mehod or function method 
//that doesnt return anything. They can accept inputs based on the generals 
//that you template on. If you need a return check out the Func Class
//example:
Action YourActionProperty = new Action(()=>{/*do something*/});
//or
Action YourActionProperty = ()=>{/*do something*/};
//or
Action<int/*Or some other types followed by others comma seperated*/> 
YourParamitarizedActionProperty =
  (x/*Each Param will be to the comma seperated types*/)=>
  {/*do some with the inputs*/});

// you can invloke them by calling their invokes.
YourActionProperty.Invoke();
YourParamitarizedActionProperty.Invoke(5);
//The last is the basic sycronous way. For a aysnc call uses
YourActionProperty.BeginInvoke();
YourParamitarizedActionProperty.BeginInvoke(5);
//although awaiting is not required should you need to await a aysnc call use
YourActionProperty.EndInvoke();

//You can also fill them with defined methods in a class if you wish, 
//but the signatures must match.
Action YourActionDefinedProperty = YourDefinedMethod;
void YourDefinedMethod()
{
  //do something
}
Comment

action c#

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

public class ActionDemo : MonoBehaviour {

	void Start(){
		Action<string> SampleAction; //action dont need an explicit delegate to be declared (Action is special kind of delegate which takes parameters but returns nothing)

		SampleAction = PrintMsg;
		SampleAction += delegate(string s) {Debug.Log("from anonymous method : "+s);} ; //using anonymous method
		SampleAction += s => Debug.Log("using lambda expression : "+s); //using lambda expression
		SampleAction ("Hello shrinath");
	}

	void PrintMsg(string msg1){
		Debug.Log ("msg : " + msg1);
	}
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: C# round number of digits after decimal point 
Csharp :: how to find player gameobject in unity 
Csharp :: unity respawn 
Csharp :: how to show process time run c# 
Csharp :: unity model ripper 
Csharp :: initialize a char array java 
Csharp :: C# extract all of a property from a list of objcets 
Csharp :: convert pdf to image c# 
Csharp :: c# nullable generic 
Csharp :: get appsettings from app.config c# .net core 
Csharp :: c# recursion formula for the factorial 
Csharp :: unity position ui element 
Csharp :: linq string comparison case insensitive 
Csharp :: create new object c# 
Csharp :: unity initialize array 
Csharp :: c# string 
Csharp :: unity soft body 
Csharp :: where to write fluent api 
Csharp :: vb.net center form in screen 
Csharp :: unity audio source 
Csharp :: entity framework with query C# 
Csharp :: how-to-add-new-column-with-value-to-the-existing-datatable 
Csharp :: private Vector3 direction; 
Csharp :: dataGridView default error dialog handle 
Csharp :: unity rotate around point 
Csharp :: c# picturebox cursor hand 
Csharp :: binding on button c# 
Csharp :: get gameobject active state 
Csharp :: install nuget package for S3 
Csharp :: unity easing out 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =