Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System;
- public class Lambda : MonoBehaviour {
- private void Update()
- {
- if (Input.GetKeyDown(KeyCode.A))
- someMethod();
- }
- void someMethod()
- {
- //Com um metodo aplicado aqui mesmo
- Action sayHello = () => { Debug.Log("Hello"); };
- sayHello();
- //Exemplo com variaveis 1
- Action<int> sendToLog = (arg) => { Debug.Log(arg); };
- sendToLog(5);
- sendToLog(-10);
- sendToLog(42);
- //Exemplo com variaveis 2
- Action<string> sendStringToLog = (arg2) => { Debug.Log(arg2); };
- sendStringToLog("AFJPOASFJ");
- sendStringToLog("oloco");
- sendStringToLog("manja d++++");
- //Com um meotodo
- Action fazAsConta = () => { Metodo(); };
- fazAsConta();
- //Com multiplos argumentos
- Action<int, string, bool> sendMultipleExpressionToLog =
- (value, description, doLog) =>
- {
- if (doLog) Debug.Log("Logging out "
- + value + " and "
- + description);
- };
- sendMultipleExpressionToLog(3, "Legal", true);
- }
- void Metodo()
- {
- print("A porcentagem sobre vendas é de: " + (6780f * 34f) / 100f);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement