Events are pretty mundane. Most often you'll be using them in response to UI or when developing components that have to inform users about state changes. Yawn.
Delegates, however, are full of awesome and win. Probably the most common use is in Linq. Linq uses lambdas all over the place, which are shorthand delegates.
var numbers = new int[]{1,2,3,4,5};
var evenStevens = numbers.Where(x => x % 2 == 0);
Another common use is in multithreading:
ThreadPool.QueueUserWorkItem(o => DoWork(o));
Where I've used them that I like the most is in HtmlHelper extension methods that mix rendering html with codebehind:
/// <summary>
/// Helps render a simple list of items with alternating row styles
/// </summary>
/// <typeparam name="T">The type of each data item</typeparam>
/// <param name="html">The HtmlHelper.</param>
/// <param name="rows">The list of items</param>
/// <param name="rowTemplate">The row template.</param>
/// <param name="evenCssClass">The even row CSS class.</param>
/// <param name="oddCssClass">The odd row CSS class.</param>
public static void SimpleList<T>(
this HtmlHelper html,
IEnumerable<T> rows,
Action<T, string> rowTemplate,
string evenCssClass,
string oddCssClass)
{
var even = false;
foreach (var row in rows)
{
rowTemplate(row, even ? evenCssClass : oddCssClass);
even = !even;
}
}
an example of its use in an aspx file:
<div id="nodes" class="scrollingBlock">>
<% Html.SimpleList(
Model.Nodes,
(d, css) =>
{%>
<div class='<%=css%>'><%=d.Name %></div>
<%}, "evenRow", "oddRow");%>
</div>