本文整理汇总了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();
}
示例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
}
示例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();
}
示例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();
}