Archive for July, 2015

Fire Custom event with custom EventArgs

Step 1- Create Custom EventArgs

public class ExtendedEventArgs : EventArgs
public string Message { get; set;}
public ExtendedEventArgs(string message)
Message = message;

Step 2 – Create Delegate to handle Which will accept this argument

public delegate int ExtendedEvent(object sender, ExtendedEventArgs e);

Step 3 – Create and attach this delegate to event

public event ExtendedEvent OnExtendEvent;

Step 4 – Attach a method to delgate

this.OnExtendEvent += ExtendedEventRaised;

Step 5 – Create handler method to get requried parameter in EventAgrs

private int ExtendedEventRaised(object sender, ExtendedEventArgs e)
return e.Message.Length;

Step 6 – Fire event on your condition

if (OnExtendEvent != null)
OnExtendEvent(null, new ExtendedEventArgs(“Saresh”));

Categories: .Net, C#