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(){ StockDisplay stockDisplay=new StockDisplay(); //create new display and stock instances Stock stock=new Stock(); stock.Register(stockDisplay); //register the grid for(int looper=0;looper < 100;looper++) { //loop 100 times and modify the ask price stock.AskPrice=looper; } stock.UnRegister(stockDisplay); //unregister the display }