• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# BinaryOp类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: BinaryOperation

        public BinaryOperation()
        {
            Console.WriteLine("***********Sync Delegate Review**********");
            ReadThread("Constructor Invoked");

            BinaryOp binOp = new BinaryOp(Addition);
            int x = 10;
            int y = 20;

            //UseBeginInvoke(binOp, x, y);
            //UseBasicCall(binOp, x, y);
            UseASyncCallBack(binOp, x, y);
        }
开发者ID:ghostmonk,项目名称:CSharpTutorials,代码行数:13,代码来源:BinaryOperation.cs


示例17: Main

        static void Main(string[] args)
        {
            // Create a BinaryOp delegate object that "points to" Simple.Add().
            SimpleMath m = new SimpleMath();
            BinaryOp b = new BinaryOp(m.Add);

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

            // Display the methods that the delegate is pointing to. And, display the classes defining those methods
            DisplayDeleateInfo(b);

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


示例18: Main

 static void Main(string[] args)
 {
     AddSubtractTwoNumbers asm = new AddSubtractTwoNumbers();
     BinaryOp a = new BinaryOp(asm.AddMethod);
     a(10, 5);
     //BinaryOp b = new BinaryOp(asm.SubtractMethod);
     a += asm.SubtractMethod;
     a(10, 5);
     //Console.WriteLine("10 + 5 equals {0}", a(10,5));
     //Console.WriteLine("10 - 5 equals {0}", a(10, 5));
     //GetDelegateDetails(a);
     //Console.WriteLine();
     //GetDelegateDetails(a);
     Console.ReadKey();
 }
开发者ID:ujjwalvaish,项目名称:LearnCSharp-ThroughProjects,代码行数:15,代码来源:Program.cs


示例19: Main

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

            // Create a BinaryOp delegate object that
            // "points to" SimpleMath.Add().
            SimpleMath m = new SimpleMath();
            BinaryOp b = new BinaryOp(m.Add);

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

            DisplayDelegateInfo(b);
            Console.ReadKey();
        }
开发者ID:JamesPinkard,项目名称:WalkthroughSolutions,代码行数:15,代码来源:Program.cs


示例20: Main

        static void Main(string[] args) {
            Console.WriteLine("Async callback delegate");
            Console.WriteLine("Main invoked on thread {0}", Thread.CurrentThread.ManagedThreadId);

            BinaryOp b = new BinaryOp(Add);

            IAsyncResult iftAR = b.BeginInvoke(10, 10, new AsyncCallback(AddComplete), "custom state object");

            while (!isDone) {
                Thread.Sleep(1000);
                Console.WriteLine("-> Doing more work in main");
            }
            Console.WriteLine("Done...");
            Console.ReadLine();
        }
开发者ID:Geronimobile,项目名称:DotNetExamIntro,代码行数:15,代码来源:Program.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# BinaryOpStorage类代码示例发布时间:2022-05-24
下一篇:
C# BinaryMessageEncodingBindingElement类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap