VB.Net Event equivalence

  • Thread starter Thread starter Brad Markisohn
  • Start date Start date
B

Brad Markisohn

Can somebody tell me the C# equivalence of the Event capability found in
VB.Net? For example:

Public Class Demo

Event Data(byval strData as string)
..
..
..
Public Function SendEvent() as Boolean
RaiseEvent Data("Here's some event data.")
Return True
End Function
..
..
..
End Class
 
Brad,

The code would be as follows:

public class Demo
{
// The data event handler name might be different, I'd have to check the
name
// produced by VB.
public delegate void DataEventHandler(string strData);

public event DataEventHandler Data;

public bool SendEvent()
{
// Create a temp variable for the delegate chain.
DataEventHandler pobjListeners = Data;

// If it is not null, then fire the event.
if (pobjListeners != null)
// Fire the event.
Data("Here's some event data.");

return true;
}
}

Hope this helps.
 
Hi Brad,

I think Nicholas's sample can be a little changed. Just use one event
handler, no need the temp DataEventHandler variable. Like this:

public class Demo
{
public delegate void DataEventHandler(string strData);

public event DataEventHandler Data;

public bool SendEvent()
{
// If it is not null, then fire the event.
if (Data!= null)
// Fire the event.
Data("Here's some event data.");

return true;
}
}

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Brad,

Does my reply make sense to you?

Please feel free to feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top