public static void Main(string[] args) { Console.WriteLine("*Simple delegate example*"); BinaryOP op = new BinaryOP(SimpleMath.Add); Console.WriteLine("10+10={0}", op(10, 10)); }
private static void DelegateMethod() { DelegateClass dg = new DelegateClass(); BinaryOP binaryOP = new BinaryOP(dg.Add); BinaryOP binaryOP2 = new BinaryOP(DelegateClass.Add2); DisplayDelegateInfo(binaryOP); DisplayDelegateInfo(binaryOP2); Console.WriteLine("the sum is " + binaryOP.Invoke(1, 2)); Console.WriteLine("the sum is " + binaryOP2(1, 2)); //public delegate int BinaryOP(int x, int y); Car car = new Car { CurrSpeed = 10, maxSpeed = 100, carIsDead = false }; //this.listOfhandlers => OnCarEngineEvent car.RegisterCarEngine(new Car.CarEngineHandler(OnCarEngineEvent)); car.RegisterCarEngine(OnCarEngineEvent); //Accelerate => OnCarEngineEvent for (int i = 0; i < 6; i++) { car.Accelerate(20); } //action func Action <string, string, int> action = new Action <string, string, int>(DisplayAction); action(" action", " message", 2); //func Func <string, string, string> func = new Func <string, string, string>(DisplayFunc); Console.WriteLine("func is {0}", func(" func", " message")); }
public BinaryNode(BinaryOP op, ExpressionNode left, ExpressionNode right) { this.op = op; this.left = left; this.right = right; }
public BinaryNode(SourcePosition position, BinaryOP op, ExpressionNode left, ExpressionNode right) : base(position) { OP = op; Left = left; Right = right; }