当前位置: 首页>>代码示例>>C#>>正文


C# BinaryOp.Invoke方法代码示例

本文整理汇总了C#中BinaryOp.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryOp.Invoke方法的具体用法?C# BinaryOp.Invoke怎么用?C# BinaryOp.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinaryOp的用法示例。


在下文中一共展示了BinaryOp.Invoke方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: main

        static void main(string[] args)
        {
            Console.WriteLine("***** Simple Delegate Example*****\n");

            // instantiate an instance of "simpleMathClass" see above
            SimpleMath m = new SimpleMath();

            // so now lets add the add method of the instance of 'simpleMath' to it.
            // 'BinaryOp is a delegates that takes 2 ints as parameters and returns an int as a result.
            BinaryOp b = new BinaryOp(m.Add);



            //invoke Add() method directly using delegate object
            Console.WriteLine("Direct invocation... 10+10 is {0}", b(10, 10));
            Console.ReadLine();

            //invoke Add() method indirectly using delegate object
            Console.WriteLine("Indirect invocation,.... 10 + 10 is {0}", b.Invoke(10, 10));
            Console.ReadLine();

            // Change the target method on the fly
            b = new BinaryOp(m.Substract);
            Console.WriteLine("Replace add with subtract");
            Console.ReadLine();

            //invoke the substract method by direactly invoking that delegate
            Console.WriteLine("Direct invocation.... 15 - 5 is {0}", b(15, 5));
            Console.ReadLine();

        }
开发者ID:MainaliT,项目名称:FirstDelegateExample,代码行数:31,代码来源:Program.cs

示例2: AddOperation

        public void AddOperation()
        {
            var d = new BinaryOp(SimpleMath.Add); //static method
            //var d2 = new BinaryOp(SimpleMath.SquareNumber); // <-- compile-time error! it is type safe!

            DisplayDelegateInfo(d);
            Console.WriteLine("10 + 10 is {0}", d(10, 10));
            Console.WriteLine("10 + 10 is {0}", d.Invoke(10, 10)); // it is equivalent
        }
开发者ID:pierangelim,项目名称:advanced-c-sharp,代码行数:9,代码来源:Delegate.cs

示例3: Main

        static void Main(string[] args) {
            BinaryOp b = new BinaryOp(SimpleMath.Add);
            Console.WriteLine("10 + 10 is {0}", b(10,10));
            Console.WriteLine("10 + 10 is {0}", b.Invoke(10, 10));  //Also ok
            Console.WriteLine();
            DisplayDelegateInfo(b);

            SimpleMath m = new SimpleMath();
            BinaryOp bInst = new BinaryOp(m.Subtract);
            DisplayDelegateInfo(bInst);

            Console.ReadLine();
        }
开发者ID:Geronimobile,项目名称:DotNetExamIntro,代码行数:13,代码来源:Program.cs

示例4: Main

        static void Main(string[] args)
        {
            // 可以通过反射来查看Binary这个类型的相关信息,也可以通过ildasm.exe反编译来查看

            BinaryOp b = new BinaryOp(SimpleMath.Add);
            Console.WriteLine("10 + 11 = {0}", b(10, 11));
            Console.WriteLine("10 + 11 = {0}", b.Invoke(10, 11));
            DisplayDelegateInfo(b);

            Car c1 = new Car("SlugBug", 100, 10);
            c1.Exploded += OnCarEngineEvent;

            c1.AboutToBlow += OnCarEngineEvent2;
            c1.AboutToBlow += OnCarEngineEvent3;

            for (int i = 0; i < 6; i++)
            {
                c1.Accelerate(20);
            }
            Console.ReadLine();
        }
开发者ID:ZLLselfRedeem,项目名称:zllinmitu,代码行数:21,代码来源:Program.cs


注:本文中的BinaryOp.Invoke方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。