Beispiel #1
0
        private void ThisWallet_OnGotSomeMoney(object sender, EventArgs e)
        {
            Wallet         thisWallet = sender as Wallet;
            MoneyEventArgs args       = e as MoneyEventArgs;
            string         _name      = thisWallet.Owner;
            int            _cash      = args.Money;
            int            _crossed   = args.ValueCrossed;

            MessageBox.Show("You have reached " + _crossed + " in your wallet!\nTotal amount in your wallet is " + _cash + "!", "Kudos " + _name + "!");
        }
Beispiel #2
0
        //declaring a private method which will be used to fire the event
        //it creates an instance of event arguments class (in this case MoneyEventArgs)
        //it checks if there are any subscriptions to the event before firing it
        private void FireEvent(int valueCrossed)
        {
            MoneyEventArgs e = new MoneyEventArgs();

            e.Money        = Money;
            e.ValueCrossed = valueCrossed;
            if (OnGotSomeMoney != null)  //checking if there are subscriptions
            {
                OnGotSomeMoney(this, e); //if there are the event will be fired with 'this' object and e EventArgs as arguments
            }
            //no action if there are no subscriptions
        }