Пример #1
0
        /// <summary>
        /// 打开端口,读取设备信息
        /// </summary>
        /// <returns></returns>
        public Boolean OpenPort()
        {
            int     ret;
            Boolean Openport = false;

            ret = sio_open(ExGlobal.Port);
            if (ret != ExGlobal.SIO_OK)
            {
                MxTool.MxShowError("sio_open", ret);
                return(Openport);
            }
            if (PortSet() == false)
            {
                sio_close(ExGlobal.Port);
                return(Openport);
            }
            getCommData.GetCommData(ExGlobal.iPort, ExGlobal.ibaudrate, ExGlobal.iparity, ExGlobal.ibytesize, ExGlobal.istopbits);
            ExGlobal.GhExit         = false;
            ExGlobal.GbOpen         = true;
            StatusConnect.Text      = "Online";
            StatusConnect.BackColor = Color.LimeGreen;
            SwitchMenu();
            this.Text = ExGlobal.ShowStatus();
            Openport  = true;
            Request_Ver();
            thReadMeas = new Thread(new ThreadStart(ReadThreadExecute))
            {
                IsBackground = true
            };
            thReadMeas.Start();
            delRead = new Mydel(ShowData);
            return(Openport);
        }
Пример #2
0
        delegate void Anonymous();    // Anonymous method invocation.

        //***************************************************************************************
        static void Main(string[] args)
        {
            Mydel del = TestFunction;       // TestFunction added to invocation list.

            del += TestFunction;            // Add another instanciation of TestFunction
                                            // to the invocation list. If return type--then last
                                            // function's return value is used.
            del("Hello there.");
            TestFunction("It's all good!"); //direct use of the function.

            Anonymous MyAnon = delegate     //Anonymous function attached to delegate.
            {
                for (int x = 0; x < 5; x++)
                {
                    System.Console.WriteLine("{0} count", x);
                }
            };

            var p = new EventAlarm(); //Publisher
            var s = new MakeSound();  //Subscriber (could have more).

            p.sound += s.soundoff;    //
            p.sounder();


            MyAnon += () => System.Console.WriteLine("Lambda baby!"); //new invocation using
                                                                      // lambda expression

            MyAnon();                                                 //call to anonymous delegate.
        }
Пример #3
0
        static void Main(string[] args)
        {
            Mydel my = new Mydel(Method);

            my += Method2;
            my();
        }
Пример #4
0
        void starrt()
        {
            trueAns   = 0;
            t.Enabled = false;

            //foreach (Button b in this.Controls)
            //{
            //    this.Controls.Remove(b);
            //}
            this.Controls.Clear();
            //ijade delegate
            Mydel del = new Mydel(genrandom);

            del += Generate;
            del += ResizeForm;
            //shoru ba 2
            del(difficulty);


            //bad az 2 sanie makhfi shodane pazel
            if (Settings.Default.speed != 0)
            {
                t.Interval = Settings.Default.speed * 1000;
            }
            else
            {
                t.Interval = 2300;
            }

            t.Enabled = true;
            t.Tick   += new EventHandler(Ticked);
            this.Text = " Level " + difficulty.ToString() + "  [email protected]";
        }
Пример #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("***Exploring the use of a lambda expression and comparing it with other techniques. ***");
            // Without using delgates or lambda expression
            Console.WriteLine(" Using a normal method.");
            int a = 21, b = 79;

            Console.WriteLine(" Invoking the Sum() method in a common way without using a delegate.");
            Console.WriteLine("Sum of {0} and {1} is : {2}", a, b, Sum(a, b));

            // Using Delegate(Initialization with a named method)
            Mydel del1 = new Mydel(Sum);

            Console.WriteLine("\n Using delegate now.");
            Console.WriteLine("Invoking the Sum() method with the use of a delegate.");
            Console.WriteLine("Sum of {0} and {1} is : {2}", a, b, del1(a, b));

            // Using anonymous method (C# 2.0 onwards)
            Mydel del2 = delegate(int x, int y) { return(x + y); };

            Console.WriteLine("\n Using anonymous method now.");
            Console.WriteLine("Invoking the Sum() method using an anonymous method.");
            Console.WriteLine("Sum of {0} and {1} is : {2}", a, b, del2(a, b));

            // Using lambda expression(C# 3.0 onwards)
            Console.WriteLine("\n Using lambda expression now.");
            Mydel sumOfTwoIntegers = (x, y) => x + y;

            Console.WriteLine("Sum of {0} and {1} is : {2}", a, b, sumOfTwoIntegers(a, b));
            Console.ReadKey();
        }
Пример #6
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button bt = sender as Button;

            if (bt.Tag.ToString() == "1")
            {
                MydelNoparameter MydelNoparameter = myclass.Add1;
                this.ReturnValue.Text = "无参无返回值的委托";
            }
            if (bt.Tag.ToString() == "2")
            {
                Mydel mydel = myclass.Add2;
                mydel += myclass.Add3;
                mydel += myclass.Add2;

                int x = Convert.ToInt32(this.Parameters.Text.ToString());
                mydel(ref x);
                this.ReturnValue.Text = x.ToString();
            }
            if (bt.Tag.ToString() == "3")
            {
                MydelReturnValue mydelReturnValue = myclass.Add4;
                this.ReturnValue.Text = mydelReturnValue().ToString();
            }
            if (bt.Tag.ToString() == "4")
            {
                MydelParameterReturn mydelParameterReturn = myclass.Add5;
                this.ReturnValue.Text = mydelParameterReturn(Convert.ToInt32(this.Parameters.Text.ToString())).ToString();
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("-----Anonymous-------- \n ");
            Mydel del = delegate(int x, int y)  //Anonymous    2.0
            {
                return(x + y);
            };

            Console.WriteLine(del(1, 2));
            Console.WriteLine(" ");

            Console.WriteLine("------Lambda------------- "); //same as above with diff method
            Mydel obj = (x, y) => x + y;                     //we do not return value here atutomatically understand type

            Console.WriteLine(obj(3, 4));


            Console.WriteLine(" ---without delegate-----");
            Func <int, int, int> fun = (x, y) => x + y;//no need to delcare delegate(without delegate).It has two values n one is return type     i.e <>

            Console.WriteLine(fun(5, 6));

            Console.WriteLine("---------Action --------- ");  //Acion has void return type
            Action <string> act = s => Console.WriteLine(s);

            act("This is a string");



            Console.Read();
        }
Пример #8
0
        static void Main(string[] args)
        {
            Console.WriteLine("*** Exploring Lambda Expression***");
            //Without using delgates or lambda expression
            int a = 25, b = 37;

            Console.WriteLine("\n Calling Sum method without using a delegate:");
            Console.WriteLine("Sum of a and b is : {0}", Sum(a, b));

            //Using Delegate( Initialization with a named method)
            Mydel del = new Mydel(Sum);

            Console.WriteLine("\n Using delegate now:");
            Console.WriteLine("Calling Sum method with the use of a delegate:");
            Console.WriteLine("Sum of a and b is: {0}", del(a, b));

            //Using Anonymous method(C# 2.0 onwards)
            Mydel del2 = delegate(int x, int y) { return(x + y); };

            Console.WriteLine("\n Using Anonnymous method now:");
            Console.WriteLine("Calling Sum method with the use of an anonymous method:");
            Console.WriteLine("Sum of a and b is: {0}", del2(a, b));

            //Using Lambda expression(C# 3.0 onwards)
            Console.WriteLine("\n Using Lambda Expresson now:");
            Mydel sumOfTwoIntegers = (x1, y1) => x1 + y1;

            Console.WriteLine("Sum of a and b is: {0}", sumOfTwoIntegers(a, b));
            Console.ReadKey();
        }
Пример #9
0
        static void Main(string[] args)
        {
            Mydel delg = new Mydel(AreaofTriangle);

            Console.WriteLine(delg(12, 25));
            delg += new Mydel(AreaofRectangle);
            Console.WriteLine(delg(12, 25));
        }
Пример #10
0
        private static void CallBackMethod(IAsyncResult ar)
        {
            Mydel  obj = (Mydel)ar.AsyncState;
            string val = obj.EndInvoke(ar);

            Console.WriteLine("callback method");
            Console.WriteLine("value returned from function: " + val.ToString());
        }
Пример #11
0
        static void Main1(string[] args)
        {
            Mydel o = show;

            Console.WriteLine("before show is called ");
            o.BeginInvoke(null, null);
            Console.ReadLine();
        }
Пример #12
0
        static void Main(string[] args)
        {
            Mydel <string> str1 = () => "1111";
            Mydel <object> obj1 = str1;

            Console.WriteLine(obj1.Invoke());
            Console.ReadKey();
        }
Пример #13
0
        static void Main3(string[] args)
        {
            Console.WriteLine("before show is called ");
            Mydel obj = show;

            obj.BeginInvoke("kawaldeep", CallBackMethod, null);
            Console.ReadLine();
        }
Пример #14
0
        static void Main4(string[] args)
        {
            Console.WriteLine("before show is called ");
            obj = show;
            IAsyncResult ar = obj.BeginInvoke("kawaldeep", CallBackMethod, null);

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Mydel delg = new Mydel(AreaRect);

            Console.WriteLine(delg(5, 6));
            delg += new Mydel(Square);

            Console.WriteLine(delg(3, 2));
        }
Пример #16
0
        static void Main()
        {
            Event_Demo e1 = new Event_Demo();

            event1 += new Mydel(e1.M1);
            event2 += new Mydel(e1.M2);
            event1(3, 4);
            event2(3, 3);
        }
Пример #17
0
        static void Main(string[] args)
        {
            Mydel del = a => Console.WriteLine(a);

            del("hello");
            Func <int, double, double> Calc = (x, y) => x * y;

            Console.WriteLine(Calc(12, 10.5));
        }
Пример #18
0
        public Form2()
        {
            d = new Mydel(GetDelegate);
            InitializeComponent();
            Form1 f1 = new Form1();

            f1.SetCBB(cbbLopSH2);
            cbbLopSH2.SelectedIndex = 0;
        }
Пример #19
0
        /// <summary>
        /// 阻塞 等待完成
        /// </summary>
        public void Break()
        {
            Mydel        del         = Sum;
            IAsyncResult asyncResult = del.BeginInvoke(5, 2, null, null);
            int          result      = del.EndInvoke(asyncResult);

            Console.WriteLine("略略略略");
            Console.WriteLine(result);
        }
Пример #20
0
        static void Main(string[] args)
        {
            Mydel delg = new Mydel(Add);

            Console.WriteLine(delg(50, 20));
            delg += new Mydel(Subtract);
            Console.WriteLine(delg(25, 10));
            delg -= new Mydel(Subtract);
            Console.WriteLine(delg(50, 20));
        }
Пример #21
0
        public static void Main()
        {
            Mydel ob = (x => { for (int i = 0; i <= x; i++)
                               {
                                   Console.WriteLine(i);
                               }
                        });

            ob(10);
        }
Пример #22
0
        static void Main(string[] args)
        {
            Mydel delg = new Mydel(add);

            Console.WriteLine(delg(67, 54));
            delg += new Mydel(subtract);
            Console.WriteLine(delg(12, 23));
            delg -= new Mydel(add);
            Console.WriteLine(delg(20, 50));
        }
Пример #23
0
        static void Main(string[] args)
        {
            Program p    = new Program();
            Mydel   del  = new Mydel(p.mes1);
            Mydel   del1 = new Mydel(p.mes2);
            Mydel   del2 = del + del1;

            del2();
            Console.ReadKey();
        }
Пример #24
0
        static void Main(string[] args)
        {
            Mydel delg = new Mydel(subtract);

            Console.WriteLine(delg(20, 50));
            delg += new Mydel(Add);
            Console.WriteLine(delg(12, 25));
            delg -= new Mydel(Add);
            Console.WriteLine(delg(20, 50));
            Square
        }
        static void Main()
        {
            DelegateExample obj = new DelegateExample();
            Mydel           del = new Mydel(obj.fun);

            del();
            del();
            del();
            del();
            Console.ReadKey();
        }
Пример #26
0
        static void Main(string[] args)
        {
            Program p   = new Program();
            Mydel   del = new Mydel(p.cal);

            p.evnt += del;
            Console.WriteLine("Enter the number");
            int a = int.Parse(Console.ReadLine());

            p.evnt.Invoke(a);
            Console.ReadKey();
        }
Пример #27
0
        static void Main(string[] args)
        {
            //var s1 = string.Format("{0}{1}", "abc", "cba");
            //var s2 = "abc" + "cba";
            //var s3 = "abccba";

            //Console.WriteLine(s1 == s2);
            //Console.WriteLine((object)s1 == (object)s2);
            //Console.WriteLine(s2 == s3);
            //Console.WriteLine((object)s2 == (object)s3);


            //var test = new Test();
            //try
            //{
            //    test.Print();
            //}
            //catch (Exception)
            //{
            //    Console.Write("5");
            //}
            //finally
            //{
            //    Console.Write("4");
            //}

            //var arr1 = new int[] { 1, 2, 3, 4, 5 };
            //var arr2 = new int[] { 2, 3, 4 };
            //for (int i = 0; i <arr2.Length; i++)
            //{
            //    arr1[i] += arr2[i];
            //}
            //foreach (var item in arr1)
            //{
            //    Console.Write($"{item} ");
            //}

            Mydel md  = new Mydel(Console.WriteLine);
            var   arr = new int[] { 1, 2, 3, 4 };

            //foreach (var i in arr)
            //{

            //    md += () => Console.WriteLine(i);
            //}
            for (int i = 0; i < arr.Length; i++)
            {
                md += () => Console.WriteLine(i);
            }
            md();
            Console.ReadKey();
        }
Пример #28
0
        static void Main(string[] args)
        {
            Console.WriteLine("before show is called ");
            Mydel obj = show;

            obj.BeginInvoke("kawaldeep", delegate(IAsyncResult ar)
            {
                string val = obj.EndInvoke(ar);
                Console.WriteLine("callback method");
                Console.WriteLine("value returned from function: " + val.ToString());
            }, null);

            Console.ReadLine();
        }
Пример #29
0
        static void Main(string[] args)
        {
            Mydel mydelegate = new Mydel(square);

            mydelegate += add;
            mydelegate += delegate(int x)
            { WriteLine("Anon called"); return(x * 10); };
            mydelegate += y => y / y;
            int j = mydelegate(78);

            WriteLine(j);
            //int  a => a * 3;
            ReadLine();
        }
Пример #30
0
        static void Main(string[] args)
        {
            Mydel del1 = new Mydel(add);
            Mydel del2 = new Mydel(sub);


            Console.WriteLine(del1(12, 12));
            Console.WriteLine(del2(10, 5));

            Mydel1 dl = new Mydel1(area);

            Console.WriteLine(dl(3));

            Console.ReadKey();
        }
Пример #31
0
        static void Main(string[] args)
        {
            Mydel del = new Mydel(Sum);

            Console.WriteLine("Before BeginInvoke...");

            IAsyncResult iar = del.BeginInvoke(3, 5, new AsyncCallback(CallWhereDone), null);


            Console.WriteLine("Doning more work in Main");

            Thread.Sleep(500);

            Console.WriteLine("Don with Main.Exiting");

            Console.ReadKey();
        }