Advertisement
Caminhoneiro

Lambda

Jul 12th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5.  
  6. public class Lambda : MonoBehaviour {
  7.  
  8.     private void Update()
  9.     {
  10.         if (Input.GetKeyDown(KeyCode.A))
  11.             someMethod();
  12.     }
  13.  
  14.     void someMethod()
  15.     {
  16.         //Com um metodo aplicado aqui mesmo
  17.         Action sayHello = () => { Debug.Log("Hello"); };
  18.         sayHello();
  19.  
  20.         //Exemplo com variaveis 1
  21.         Action<int> sendToLog = (arg) => { Debug.Log(arg); };
  22.         sendToLog(5);
  23.         sendToLog(-10);
  24.         sendToLog(42);
  25.  
  26.         //Exemplo com variaveis 2
  27.         Action<string> sendStringToLog = (arg2) => { Debug.Log(arg2); };
  28.         sendStringToLog("AFJPOASFJ");
  29.         sendStringToLog("oloco");
  30.         sendStringToLog("manja d++++");
  31.  
  32.         //Com um meotodo
  33.         Action fazAsConta = () => { Metodo(); };
  34.         fazAsConta();
  35.  
  36.         //Com multiplos argumentos
  37.         Action<int, string, bool> sendMultipleExpressionToLog =
  38.         (value, description, doLog) =>
  39.         {
  40.             if (doLog) Debug.Log("Logging out "
  41.                 + value + " and "
  42.                 + description);
  43.         };
  44.         sendMultipleExpressionToLog(3, "Legal", true);
  45.  
  46.     }
  47.  
  48.  
  49.  
  50.     void Metodo()
  51.     {
  52.         print("A porcentagem sobre vendas é de: " + (6780f * 34f) / 100f);
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement