コード例 #1
0
ファイル: Program.cs プロジェクト: deepakorantak/DotNet
        static void Main(string[] args)
        {
            // Custom delegate implememtation with custom parameters
            CustomDelegateCustomArgs c1 = new CustomDelegateCustomArgs();

            c1.DoWork(6, 3);

            // Custom delegate but standard parameters with sender object and Eventargs
            //MathOperationArgs is inherited from EventArgs
            MathOperationArgs e = new MathOperationArgs();

            e.x = 10;
            e.y = 5;

            CustomDelegateEventArgs c2 = new CustomDelegateEventArgs();

            c2.DoWork(c2, e);


            // Eventhandler delegate with standard parameters with sender object and Eventargs
            //MathOperationArgs is inherited from EventArgs
            MathOperationArgs ab = new MathOperationArgs();

            ab.x = 15;
            ab.y = 3;

            EventHandlerDelgate c3 = new EventHandlerDelgate();

            c3.DoWork(c3, ab);

            // Eventhandler delegate using lambda with standard parameters with sender object and Eventargs with
            //MathOperationArgs is inherited from EventArgs
            MathOperationArgs eb = new MathOperationArgs();

            eb.x = 3;
            eb.y = 6;

            EventHandlerUsingLambda c4 = new EventHandlerUsingLambda();

            c4.DoWork(c4, eb);

            //action T delgate
            ActionTDelagate c5 = new ActionTDelagate();

            c5.ProcessData(6, 5, c5.OperationAdd);
            c5.ProcessData(6, 5, c5.OperationSubstract);
            c5.ProcessData(6, 5, c5.OperationMultiply);
            c5.ProcessData(6, 5, c5.OperationDivision);

            //function T delgate
            FunctionTDelegate c6 = new FunctionTDelegate();

            c6.ProcessData(7, 2, c6.OperationAdd);
            c6.ProcessData(7, 2, c6.OperationSubstract);
            c6.ProcessData(7, 2, c6.OperationMultiply);
            c6.ProcessData(7, 2, c6.OperationDivision);
        }
コード例 #2
0
 private void Divide(object a, MathOperationArgs e)
 {
     Console.WriteLine($"Division {e.x} / {e.y} = { e.x / e.y } ");
 }
コード例 #3
0
 private void Multiply(object a, MathOperationArgs e)
 {
     Console.WriteLine($"Multiplication {e.x} * {e.y} = { e.x * e.y } ");
 }
コード例 #4
0
 private void Substract(object a, MathOperationArgs e)
 {
     Console.WriteLine($"Substraction {e.x} - {e.y} = { e.x - e.y } ");
 }
コード例 #5
0
 private void Add(object a, MathOperationArgs e)
 {
     Console.WriteLine($"Addition {e.x} + {e.y} = { e.x + e.y } ");
 }
コード例 #6
0
 public void DoWork(object a, MathOperationArgs e)
 {
     Operation(a, e);
 }
コード例 #7
0
 public void DoWork(object s, MathOperationArgs e)
 {
     Operation(s, e);
 }