Einzelnen Beitrag anzeigen

Benutzerbild von Phoenix
Phoenix
(Moderator)

Registriert seit: 25. Jun 2002
Ort: Hausach
7.606 Beiträge
 
#3

Re: Dieses Delphi-Event in C#?

  Alt 4. Aug 2006, 09:36
Code:
public delegate void MyEventDelegate(Int32 int1, Int32 int2);

public class TMyClass : Object
{
    public event MyEventDelegate MyEvent;

    private void SomeProc()
    {
        MyEvent(2, 5);
    }
}

public class Subscriber : Object
{
    public TMyClass myclass;

    public Subscriber()
    {
        myclass = new TMyClass();
        myclass.MyEvent += new MyEventDelegate(onEvent);
    }

    private void onEvent(Int32 a, Int32 b)
    {
        Int32 c = a + b;
    }
}

Und noch ein Edit: Nachtrag: http://www.codeproject.com/csharp/eventdrivenmodel.asp
Sebastian Gingter
Phoenix - 不死鳥, Microsoft MVP, Rettungshundeführer
Über mich: Sebastian Gingter @ Thinktecture Mein Blog: https://gingter.org
  Mit Zitat antworten Zitat