Codigo 1
==========================================
public delegate void DelegateType(string message);
Codigo 2
==========================================
public static void Method(string message)
{
System.Console.WriteLine(message);
}
Función cualquiera con la misma firma que DelegateType es decir void xxx(string yyy)
Codigo 3
==========================================
DelegateType handler = Method; //Esto es posible xq DelegateType es una referencia
//a funciones con la firma void xxx(string yyy).
handler("Hello World"); //Llama a Method
Codigo 4
==========================================
public void MethodWithCallback(int param1, int param2, DelegateType callback)
{
callback("The number is: " + (param1 + param2).ToString());
}
Codigo 5
==========================================
MethodWithCallback(1, 2, handler); //Llamada enviando una referencia a Method
Codigo 6
==========================================
public void Method1(string message) { }
public void Method2(string message) { }
DelegateType d1 = Method1;
DelegateType d2 = Method2;
DelegateType d3 = Method;
DelegateType allMethodsDelegate = d1 + d2;//assigna referencia a d1 y d2
allMethodsDelegate += d3; //agrega referencia a una tercera funcion
Codigo 8
==========================================
allMethodsDelegate -= d1; //elimina d1 de la lista de referencias
DelegateType oneMethodDelegate = allMethodsDelegate - d2; //Copia todos menos d2
Codigo 9
==========================================
int invocationCount = d1.GetInvocationList().GetLength(0); //Cantidad de referencias
Codigo 10
==========================================
using System.Reflection;
namespace DemoDelegate
{
public delegate void D();
public class ComprobaciónDelegados
{
public static void Main()
{
Type t = typeof(ComprobaciónDelegados);
MethodInfo m = t.GetMethod("Metodo1");
D obj = (D) Delegate.CreateDelegate(typeof(D), m);
obj();
}
public static void Metodo1()
{ Console.WriteLine("Ejecutado Método1"); }
public static void Metodo2(string s)
{ Console.WriteLine("Ejecutado Método2");
}
}
}
Thursday, May 13, 2010
Subscribe to:
Post Comments (Atom)
-
Resources: [1] Hela https://ome.grc.nia.nih.gov/iicbu2008/hela/index.html
-
en inglés se llama “A potentially dangerous Request.Form value was detected from the client”. varias páginas indican dos cosas: 1. agrega...
-
mas plugins http://devsnippets.com/reviews/using-jquery-to-style-design-elements-20-impressive-plugins.html http://www.extjs.com/deploy/dev/...
PostgreSQL json fields
select name->'es_PE',* from product_template where name->>'es_PE' like '%MEGACI%' References: [1] https:/...
No comments:
Post a Comment