static void Main(string[] args) { Console.WriteLine("Delegate example:\n"); // объявляем переменные-делегаты // создаём и инициализируем объекты Simple ps = new Simple(2, 2); IntOp a = new IntOp(ps.Add); // анонимный метод IntOp s = delegate(int ax, int ay) { return(ax - ay); }; // ещё один с лямбда выражением: IntOp s1 = (int ax, int ay) => { return(ax - ay); }; // ещё короче: IntOp s2 = (int ax, int ay) => (ax - ay); TOp <int> m = Simple.Mul; TOp <int> d = new TOp <int>(Simple.Div); int x = 100, y = 50; // вызовы через переменные-делегаты: Console.WriteLine("a({0}, {1}) = {2}", x, y, a(x, y)); Console.WriteLine("s({0}, {1}) = {2}", x, y, s(x, y)); Console.WriteLine("s1({0}, {1}) = {2}", x, y, s1(x, y)); Console.WriteLine("s2({0}, {1}) = {2}", x, y, s2(x, y)); Console.WriteLine("m({0}, {1}) = {2}", x, y, m(x, y)); Console.WriteLine("d({0}, {1}) = {2}", x, y, d(x, y)); }
public NodeOperator(TOp comparer) { this.comparer = comparer; }
public Apply() { poperateur = TOp.Null; pargument1 = pargument2 = null; }