In the following code I need to know the syntax of passing two strings when the event is raised.
[PublishEvent("Click")]
public event EventHandler<EventArgs<string>> MyEvent;
Thanks, Saxon.
The cleanest way is to create your own class that derives from EventArgs
:
public class MyEventArgs : EventArgs
{
private readonly string _myFirstString;
private readonly string _mySecondString;
public MyEventArgs(string myFirstString, string mySecondString)
{
_myFirstString = myFirstString;
_mySecondString = mySecondString;
}
public string MyFirstString
{
get { return _myFirstString; }
}
public string MySecondString
{
get { return _mySecondString; }
}
}
And use it like this:
public event EventHandler<MyEventArgs> MyEvent;
To raise the event, you can do something like this:
protected virtual void OnMyEvent(string myFirstString, string mySecondString)
{
EventHandler<MyEventArgs> handler = MyEvent;
if (handler != null)
handler(this, new MyEventArgs(myFirstString, mySecondString));
}
Make your class and extend for EventArgs, and pass it
public class YourCustomeEvent : EventArgs
{
public string yourVariable {get; }
}
Now you have to provide your custom class like this
public event EventHandler<YourCustomeEvent> MyEvent;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With