I have a static array list in class called cart, is there a way to implement event listener to be used by other classes? I am new to c# tried to understand PropertyChangedEventHandler with no success. The arraylist and property are initialized as below:
private static ArrayList cartList = new ArrayList();
public static ArrayList CartList
{
get { return cartList; }
set
{
cartList = value;
}
}
Edit:
Altered @KMC code to work with List by hiding base methods:
public class ListOfProducts : List<Product>
{
public void Add(Product obj)
{
base.Add(obj);
this.OnChange();
}
public void UpdateLast(Product obj)
{
base[base.Count - 1] = obj;
this.OnChange();
}
public void Remove(Product obj)
{
base.Remove(obj);
this.OnChange();
}
public void Clear()
{
base.Clear();
this.OnChange();
}
public event EventHandler Change;
protected void OnChange()
{
if (this.Change != null)
{
this.Change(this, new EventArgs() { });
}
}
}