static void Main(string[] args) { //create new display and stock instances StockDisplay stockDisplay = new StockDisplay(); StockDisplay stockDisplay1 = new StockDisplay(); Stock stock = new Stock(); Stock.AskPriceDelegate aDelegate = new Stock.AskPriceDelegate(stockDisplay.AskPriceChanged); Stock.AskPriceDelegate bDelegate = new Stock.AskPriceDelegate(stockDisplay1.AskPriceChanged); stock.AskPriceChanged += aDelegate; stock.AskPriceChanged += bDelegate; for (int looper = 0; looper < 10; looper++) { stock.AskPrice = looper; } stock.AskPriceChanged -= aDelegate; for (int looper = 0; looper < 10; looper++) { stock.AskPrice = looper; } stock.AskPriceChanged -= bDelegate; Console.ReadKey(); }
public static void Main() { //create new display and stock instances var stockDisplay = new StockDisplay(); var stock = new Stock(); //create a new delegate instance and bind it //to the observer's askpricechanged method var aDelegate = new Stock.AskPriceDelegate(stockDisplay.AskPriceChanged); //add the delegate to the event stock.AskPriceChanged += aDelegate; //loop 100 times and modify the ask price for (var looper = 0; looper < 100; looper++) { stock.AskPrice = looper; } //remove the delegate from the event stock.AskPriceChanged -= aDelegate; Console.WriteLine("Complete.."); Console.ReadLine(); }
public void TestFunction() { Ag.LogDouble(" Test Function >>>> "); //create new display and stock instances StockDisplay stockDisplay = new StockDisplay(); Stock stockObj = new Stock(); //create a new delegate instance and bind it //to the observer's askpricechanged method Stock.AskPriceDelegate aDelegate = new Stock.AskPriceDelegate(stockDisplay.AskPriceChanged); // DlgtType dlgtObject = new DlgtType ( function ); // 대리자 객체 생성. //add the delegate to the event stockObj.AskPriceChangedDlgt += aDelegate; // anInstance.aMember += dlgtObject ; //loop 100 times and modify the ask price for (int looper = 0; looper < 100; looper++) { stockObj.AskPrice = looper; } //remove the delegate from the event stockObj.AskPriceChangedDlgt -= aDelegate; }
public static void Main() { //create new display and stock instances var stockDisplay = new StockDisplay(); var stock = new Stock(); //create a new delegate instance and bind it //to the observer's askpricechanged method var aDelegate = new Stock.AskPriceDelegate(stockDisplay.AskPriceChanged); //add the delegate to the event stock.AskPriceChanged += aDelegate; //loop 100 times and modify the ask price for (var looper = 0; looper < 100; looper++) { stock.AskPrice = looper; } //remove the delegate from the event stock.AskPriceChanged -= aDelegate; Console.WriteLine("Complete.."); Console.ReadLine(); } //Main