protected virtual void OnPriceChanged(PriceChangedEventArgs e) { if (e.NewPrice > 200) { PriceChanged.Invoke(this, e); // removed null check because the object is already initialized. } }
private void OnPriceUpdate() { PriceChanged?.Invoke(this, new PriceUpdateEventArgs() { Row = Row, AlertId = Alerts.IndexOf(this) }); }
protected virtual void OnPriceChanged(EventArgs e) { if (PriceChanged != null) { PriceChanged.Invoke(this, e); } }
//методы public void ChangePrice(int value) { Price = value; var args = new PriceChangedEventArgs(); args.NewPrice = value; PriceChanged?.Invoke(this, args); }
private void RecalculatePrice() { CafeItemInfo.TotalPrice = ItemCheckbox.Checked ? CafeItemInfo.Price * CafeItemInfo.Count : 0; PriceChanged?.Invoke(this, CafeItemInfo.TotalPrice); }
public void OnPriceChange(PriceChangedEventAgrs e) { PriceChanged?.Invoke(this, e); //if (PriceChanged != null) //{ // PriceChanged(this, e); //} }
protected virtual void OnPriceChanged(PriceChangedEventArgs e) { //when there is method is added to PriceChanged event delegate if (PriceChanged != null) { //invoke the method: // stock_PriceChanged(object sender, PriceChangedEventArgs e) PriceChanged.Invoke(this, e); } }
/// <summary> /// Simulates a change in stock price. Rules are: /// 1) New price is within -/+ 10 % of the current price. /// 2) New price must be at most equal to upper limit. /// 3) New price must be at least equal to lower limit. /// </summary> public void GenerateNewPrice() { int percentChange = 10 - _generator.Next(21); double factor = 1 + (percentChange / 100.0); double newPrice = _price * factor; if (newPrice > _upperLimit) { newPrice = _upperLimit; } if (newPrice < _lowerLimit) { newPrice = _lowerLimit; } Price = newPrice; PriceChanged?.Invoke(ID, Price); }
public event EventHandler <PriceChangedEventArgs> PriceChanged; // 2 & 3 Use Framework define generic delegate protected virtual void OnPriceChanged(PriceChangedEventArgs e) // Protected Virtual Method that fires the event { PriceChanged?.Invoke(this, e); }
protected virtual void OnPriceChanged(PriceChangedEventArgs e) { PriceChanged?.Invoke(this, e); }
// The Standard Event Pattern requires a protected virtual method that fires the event. // The name has to match the name of the event, prefixed with the word "On". // It has to accept a single EventArgs argument protected virtual void OnPriceChanged(PriceChangedEventArgs e) { // This is a thread-safe and succint way to envoke the event. PriceChanged?.Invoke(this, e); }
private void OnPriceChanged(decimal pretVechi, decimal pretNou) //functie care aplica delegatul cand trebuie { PriceChanged?.Invoke(this, new PriceChangedArgs { PretNou = pretNou, PretVechi = pretVechi }); }
private void OnMatch(object sender, RealtimeMatch e) { this.Price = e.Price.Value; PriceChanged?.Invoke(this, e.Price.Value); }
void OnPriceChanged(int priceChange) { PriceChanged?.Invoke(this, priceChange); }
public void ChangePrice(float price) { Price = price; PriceChanged?.Invoke(this, price); }
public event EventHandler <PriceChangedEventArgs> PriceChanged; // "Po zdefiniowaniu podklasy klasy EventArgs jest wybór lub zdefiniowanie delegatu dla zdarzenia" //public event EventHandler PriceChanged; protected virtual void OnPriceChanged(PriceChangedEventArgs e) // "I w końcu wzorzec zakłada napisanie chronionej metody wirtualnej uruchamiającej zdarzenie." { PriceChanged?.Invoke(this, e); }
public void Test() { PriceChanged?.Invoke(this, new PriceChangedEventArgs(1, 1)); }
// any method inside of Stock class can call the event, which then triggers subscribers protected virtual void OnPriceChanged(PriceChangedEventArgs e) { PriceChanged?.Invoke(this, e); // null propagation, will check for null before invocation }