Was sind VORDEFINIERTE DELEGATES

 

 

 

Program.CS Button.CS  

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Delegaten_und_Events

// Action - Func

{
class Program
{
static void Main(string[] args)
{
Button b = new Button();
b.KlickEvent += new EventHandler(MeineKlickMethode);

b.Click();

//Action del = new Action(MeineKlickMethode);
//del();

Action<int> del2 = new Action<int>(MeineKlickMethode);
del2(2);


}

static void MeineKlickMethode(object sender, System.EventArgs args)
{
Console.WriteLine("Dies ist ein Mustertext");

Console.ReadKey();
}

static void MeineKlickMethode(int parameter)
{
Console.WriteLine("Dies ist ein Mustertext");

Console.ReadKey();
}

}
}

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Delegaten_und_Events
{


class Button
{
public event EventHandler KlickEvent;

public void Click()
{
if (KlickEvent != null)
KlickEvent(this, System.EventArgs.Empty);
}
}

public delegate void KlickHandler();

}

Top