delegate c# asp mvc code example
Example: delegate c# mvc
using System;
namespace MVC
{
public class Book
{
// declare a delegate for the bookpricechanged event
public delegate void BookPriceChangedHandler(objectsender,
BookPriceChangedEventArgs e);
// declare the bookpricechanged event using the bookpricechangeddelegate
public event BookPriceChangedHandlerBookPriceChanged;
// instance variable for book price
object _bookPrice;
// property for book price
public object BookPrice
{
set
{
// set the instance variable
_bookPrice=value;
// the price changed so fire the event!
OnBookPriceChanged();
}
}
// method to fire price canged event delegate with proper name
// this is the method our observers should be implenting!
protected void OnBookPriceChanged()
{
BookPriceChanged(this, new BookPriceChangedEventArgs(_bookPrice));
}
}
}