Sign in to follow this  
Kryptus

C# Events

Recommended Posts

I'm finding C# events to be a bit hard to learn. I understand them in VB but it's a lot different in C#. In VB I would use the following for example: Client is a network class I have created and also contains events that are raised when a client connects, disconnects, etc. Dim myClient As Client AddHandler myClient.Connected, AddressOf OnConnected AddHandler myClient.Disconnected, AddressOf OnDisconnected Public Sub OnConnected() Console.WriteLine("User has connected") End Sub That's the gist. I hope you understand, being that it's just an example. How would I complete the same in C#? I have some events already declared as delegates and events but I don't know how to "AddHandler" or so to speak. Thanks.

Share this post


Link to post
Share on other sites
d3d_device.DeviceLost += new System.EventHandler(this.OnLostDevice);

Taken from my Direct3D wrapper. Of course, it depends on the type of the event you want to override.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this