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


C# BinaryOp类代码示例

本文整理汇总了C#中BinaryOp的典型用法代码示例。如果您正苦于以下问题:C# BinaryOp类的具体用法?C# BinaryOp怎么用?C# BinaryOp使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BinaryOp类属于命名空间,在下文中一共展示了BinaryOp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Main

        static void Main(string[] args)
        {
            Console.WriteLine("***** Async Delegate Invocation *****");

            // Print out the ID of the executing thread.
            Console.WriteLine("Main() invoked on thread {0}.",
              Thread.CurrentThread.ManagedThreadId);

            BinaryOp b = new BinaryOp(Add);
            IAsyncResult iftAR = b.BeginInvoke(10, 10, null, null);

            // This message will keep printing until
            // the Add() method is finished.
            while (!iftAR.IsCompleted)
            {
                Console.WriteLine("Doing more work in Main()!");
                Thread.Sleep(1000);
            }

            // Now we know the Add() method is complete.
            int answer = b.EndInvoke(iftAR);

            Console.WriteLine("10 + 10 is {0}.", answer);
            Console.ReadLine();
        }
开发者ID:usedflax,项目名称:flaxbox,代码行数:25,代码来源:Program.cs

示例3: Main

        static void Main(string[] args)
        {
            BinaryOp opCode = new BinaryOp(Add);
            Console.WriteLine("Threading!");
            Thread t = System.Threading.Thread.CurrentThread;
            Console.WriteLine(t.IsAlive);
            AppDomain ad = Thread.GetDomain();
            Console.WriteLine(ad.FriendlyName);
            System.Runtime.Remoting.Contexts.Context ctx = Thread.CurrentContext;

            Console.WriteLine("\nMain() thread id: {0}", Thread.CurrentThread.ManagedThreadId);
            //Console.WriteLine("waits till Add completes, delegate sum: {0}", opCode.Invoke(10, 30));
            //IAsyncResult iAsync = opCode.BeginInvoke(10, 50, null, null);
            //the called thread informs the primary thread that it hascompleted
            IAsyncResult iAsync = opCode.BeginInvoke(10, 50, new AsyncCallback(AddComplete), "author: naynish c");
            Console.WriteLine("Add called async");
            //keeps on asking if the call is complete
            Console.WriteLine("Check if Add is complete {0}", iAsync.IsCompleted);
            //waits for 200 milliseconds and asks if the call is complete
            iAsync.AsyncWaitHandle.WaitOne(200);
            Console.WriteLine("Check if Add is complete {0}", iAsync.IsCompleted);
            //Console.WriteLine("Sum: {0}", opCode.EndInvoke(iAsync));
            Console.WriteLine("Check if Add is complete {0}", iAsync.IsCompleted);
            ThreadProperties.Basics();
            Console.ReadLine();
        }
开发者ID:naynishchaughule,项目名称:CSharp,代码行数:26,代码来源:Program.cs

示例4: ExprBinary

 public ExprBinary(Ctx ctx, BinaryOp op, TypeReference type, Expr left, Expr right)
     : base(ctx) {
     this.Op = op;
     this.type = type;
     this.Left = left;
     this.Right = right;
 }
开发者ID:chrisdunelm,项目名称:DotNetWebToolkit,代码行数:7,代码来源:ExprBinary.cs

示例5: WaitCall

        static void WaitCall()
        {
            Console.WriteLine("***** Async Delegate Review *****");
            // Print out the ID of the executing thread.
            Console.WriteLine("Main() invoked on thread {0}.",
            Thread.CurrentThread.ManagedThreadId);
            // Invoke Add() in a asynchronous manner.
            BinaryOp b = new BinaryOp(Add);

            IAsyncResult res = b.BeginInvoke(10, 10, null, null);

            //while (!res.IsCompleted)
            //{
            //    Console.WriteLine("Doing more work in Main()!");
            //    Thread.Sleep(1000);
            //}
            while (!res.AsyncWaitHandle.WaitOne(1000, true))
            {
                Console.WriteLine("Doing more work in Main()!");
            }

            //Obtain results from Add
            int answer = b.EndInvoke(res);
            Console.WriteLine("10 + 10 is {0}.", answer);
        }
开发者ID:wordtinker,项目名称:c-sharp,代码行数:25,代码来源:Program.cs

示例6: Main

 static void Main(string[] args)
 {
     Console.WriteLine("***** Async Delegate Invocation *****");
     Console.WriteLine("Main() invoked on thread {0}", Thread.CurrentThread.ManagedThreadId);
     BinaryOp b = new BinaryOp(Add);
     IAsyncResult iftAR = b.BeginInvoke(10, 10, new AsyncCallback(AddComplete), "Main() thanks you for adding these numbers.");
     // using the member method or property of IAsyncResult
     // involve in Async process.
     //while (!iftAR.IsCompleted)
     //{
     //    Console.WriteLine("Doing more work in Main()");
     //    Thread.Sleep(1000);
     //}
     //while (!iftAR.AsyncWaitHandle.WaitOne(1000, true))
     //{
     //    Console.WriteLine("Doing more work in Main()");
     //}
     while (!isDone)
     {
         Thread.Sleep(1500);
         Console.WriteLine("Woring more work in Main()");
     }
     // 让第二个线程通知访问线程,当第二个线程的工作完成时。
     // 向BeginInvoke中传入AsyncCallback delegate,在BeginInvoke的异步调用结束时,
     // AsyncCallback委托会访问一个特殊的方法。
     // AsyncCallback委托的原型:     public delegate void AsyncCallback(IAsyncResult ar);
     //int answer = b.EndInvoke(iftAR);
     //Console.WriteLine("10 + 10 is {0}", answer);
     Console.WriteLine("Async work is complete!!");
     Console.ReadLine();
 }
开发者ID:ZLLselfRedeem,项目名称:zllinmitu,代码行数:31,代码来源:Program.cs

示例7: Main

 public static void Main()
 {
     BinaryOp b = new BinaryOp(SimpleMath.Add);
     // b(10,5) �ϸ� �����δ� b.Invoke(15,5) �� ����
     Console.WriteLine("b(10,5) = {0}",b(10,5)); // = 15
     b = new BinaryOp(SimpleMath.Subtract);
     Console.WriteLine("b(10,5) = {0}", b(10,5)); // = 5
 }
开发者ID:joonhwan,项目名称:study,代码行数:8,代码来源:SimpleDelegateTest.cs

示例8: BinaryExpression

        public BinaryExpression(AbstractExpression exp, BinaryOp op, string yVarName)
        {
            _xExp = exp;
            _yVarName = yVarName;

            _op = op;
            _scenario = Scenario.ExpVar;
        }
开发者ID:solarplexus6,项目名称:Oop,代码行数:8,代码来源:BinaryExpression.cs

示例9: Visit

 //Fold arithmetic and bitwise operations
 public override void Visit(BinaryOp<int, TypedExpression<int>> node)
 {
     if (node.Left is Number && node.Right is Number) {
         Console.WriteLine("Folding {0} into {1}", node, node.TypedValue);
         int pos = node.Parent.ChildNodes.IndexOf(node);
         node.Parent[pos] = new Number(node.TypedValue);
     }
 }
开发者ID:einaregilsson,项目名称:While-Language,代码行数:9,代码来源:FoldConstantExpressions.cs

示例10: 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

示例11: DelegateSync

 private static void DelegateSync()
 {
     Console.WriteLine("***** Synch Delegate Review *****");
     Console.WriteLine("Main() invoked on thread {0}.", Thread.CurrentThread.ManagedThreadId);
     BinaryOp b = new BinaryOp(Add);
     int answer = b(10, 10);
     Console.WriteLine("Doing more work in Main()");
     Console.WriteLine("10 + 10 is {0}", answer);
     Console.ReadLine();
 }
开发者ID:ZLLselfRedeem,项目名称:zllinmitu,代码行数:10,代码来源:Program.cs

示例12: Main

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

			BinaryOp binary = new BinaryOp(SimpleMath.Add);// create BinaryOp delegate obj 'points to' SimpleMath.Add
			DisplayDelegateInfo(binary);
			//invoke Add()
			Console.WriteLine("10 + 10 = {0}", BinaryOp(10, 10));
			Console.ReadLine();
		}
开发者ID:neziry,项目名称:Argeset,代码行数:10,代码来源:Main.cs

示例13: Test_1

        public static int Test_1() {
            var s = new BinaryOp(Substract);
            s += Summ;
            s += Substract;
            s += Summ;
            Console.WriteLine($"s(5,7) = {s(5, 7)}");
            s -= Summ;
            Console.WriteLine($"s(5,7) = {s(5, 7)}");

            return 0;
        }
开发者ID:JohnPaine,项目名称:learning,代码行数:11,代码来源:BasicDelegateTests.cs

示例14: Main

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

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

            DisplayDelegateInfo(b);

            Console.ReadLine();
        }
开发者ID:volkoff-pro,项目名称:Troelsen.CSharp,代码行数:11,代码来源:Program.cs

示例15: 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


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