예제 #1
0
        static void Main(string[] args)
        {
            dele d = a => a + 1;
            int  k = d(3);

            Console.WriteLine("k = " + k);
        }
예제 #2
0
        static void Main(string[] args)
        {
            //Lambda式可以被赋值给一个委托类型:
            dele myDelegate = x => x * x;
            //例子中的Lambda式中并没有任何类型的声明。是编译器为我们做了相应的隐式数据类型转换:输入参数类型能够从委托的输入参数类型隐式转换,返回类型能够被隐式转换为委托的返回类型。
            int j = myDelegate(5); //j = 25

            Console.WriteLine("j:{0}", j);

            //也可以被用于创建一个表达式树类型:
            Expression <dele> exp = x => x * x;

            //操作符“=>”具有和“=”一样的运算优先级,且为右相关(右边先执行)。

            Program p = new Program();

            p.TestMethod(5);

            // Prove that del2 still has a copy of
            // local variable j from TestMethod. //j的引用超出了原先定义的作用域
            bool result = p.del2(10);


            // Output: True
            Console.WriteLine(result);


            Console.ReadKey();
        }
예제 #3
0
파일: Hilos.cs 프로젝트: AlfredoCU/SO
        // Método a enviar al Hilo.
        public void Metodo()
        {
            int  num        = 10;
            dele elDelegado = new dele(Mover);

            if (Thread.CurrentThread.Name.Equals("Shape0"))
            {
                elDelegado.Invoke(num);
            }
            else if (Thread.CurrentThread.Name.Equals("Shape1"))
            {
                elDelegado.Invoke(num);
            }
            else if (Thread.CurrentThread.Name.Equals("Shape2"))
            {
                elDelegado.Invoke(num);
            }
            else if (Thread.CurrentThread.Name.Equals("Shape3"))
            {
                elDelegado.Invoke(num);
            }
            else if (Thread.CurrentThread.Name.Equals("Shape4"))
            {
                elDelegado.Invoke(num);
            }
            else if (Thread.CurrentThread.Name.Equals("Shape5"))
            {
                elDelegado.Invoke(num);
            }
            else
            {
                // No hay más hilos.
            }
        }
예제 #4
0
        static void Main()
        {
            dele d = delegate(int a) { return(a + 1); };
            int  k = d(3);

            Console.WriteLine("k = " + k);
        }
예제 #5
0
        delegate int dele(int x, int y);//dele is just like a class

        static void Main(string[] args)
        {
            Wouter w = new Wouter();
            dele   d = w.AddNumbers; // this is very important, calling the method and NO ()

            //VERY IMPORTANT THIS IS THE DELEGATE CALL.
            //MAKING USE OF DELEGATES SAME DATA DIFFERENT METHOD NAME AND REQUIREMENT
            //BY CALLING MULTIPLYNUMBERS METHOD
            Console.WriteLine("Making use of delegate.");
            Console.WriteLine(d(4, 6));
            d = w.MultiplyNumbers;
            Console.WriteLine(d(4, 6));
            d = w.DevideNumbers;
            Console.WriteLine(d(4, 6));
            d = w.MinusNumber;
            Console.WriteLine(d(4, 6));
            d = w.DoAwesomeAlgo;
            Console.WriteLine(d(4, 6));
            d = w.DoComplexAlgo;
            Console.WriteLine(d(4, 6));

            Console.WriteLine();


            Console.WriteLine("NON DELEGATE OPTION");
            Console.WriteLine(w.AddNumbers(3, 3));
            Console.WriteLine(w.MultiplyNumbers(4, 5));
            Console.WriteLine(w.DevideNumbers(445, 3));
        }
예제 #6
0
        static void Main(string[] args)
        {
            dele d = new dele(method);
            del  A = new del(mmethod);

            // boy d = new boy();
            // d.print ();
            // father f = new father(2);
            //  f.print();
            //father b = new boy();
            //b.print();
            //  d.print();
            boy b = new boy();

            b.print();
            father f = new boy();

            f.print();
            //   boy b = new father(); mistake can't
            //  b.print();
            Console.WriteLine(b.x);
            Console.WriteLine(f.x);
            father p = new father();

            Console.WriteLine(p.x); //  it's from virtual  from father class
            Console.WriteLine(b.x); // the same but from boy class after editing from boyy class
            Console.WriteLine(f.x); // print from father boy class as the refreence is faher but it print form boy
        }
예제 #7
0
 static void Main()
 {
     dele d;
     d = new dele(Method1);
     d(12);
     d = new dele(Method2);
     d(34);
 }
        static void Main()
        {
            dele d = delegate(int a, int b)
            { return(a + b); };
            int k = d(2, 3);

            Console.WriteLine(k);
        }
예제 #9
0
        static void Main(string[] args)
        {
            dele d = new dele(methods.sqr);

            d += new dele(methods.cube);
            d += new dele(methods.factorial);
            d(5);
        }
예제 #10
0
        static void Main(string[] args)
        {
            methods m = new methods();
            dele    d = new dele(m.sqr);

            d += new dele(m.cube);
            d += new dele(m.factorial);
            d(5);
        }
예제 #11
0
        static void Main(string[] args)
        {
            dele d;

            d = new dele(Method1);
            d(12);
            d = new dele(Method2);
            d(34);
        }
예제 #12
0
    static void Main()
    {
        dele del = new dele(Oper.Add);

        del += new dele(Oper.Sub);
        del(4, 2);
        del -= new dele(Oper.Sub);
        del(1, 9);
        Console.Read();
    }
예제 #13
0
 /// <summary>
 /// 添加委托
 /// </summary>
 public static void adddelegate()
 {
     if (real_s == null)
     {
         real_del = real_s.Gv_init;
     }
     if (_type_s == null)
     {
         _type_dele = _type_s.refresh;
     }
 }
예제 #14
0
        //static int Add(int a, int b)
        //{
        //    return a + b;
        //}
        static void Main(string[] args)
        {
            dele d = delegate(int a, int b)
            { return(a + b); };

            int k = d(2, 3);

            //int k = Add(2, 3);

            Console.WriteLine(k);
        }
예제 #15
0
        static void Main(string[] args)
        {
            dele obj = (dele)Delegate.Combine(new dele(subtract), new dele(add));

            Console.WriteLine(obj(20, 10));

            //dele obj = add;
            //Console.WriteLine( obj(10, 20));
            //obj = subtract;
            //Console.WriteLine( obj(20,10) );
            Console.ReadLine();
        }
예제 #16
0
    public static void Main()
    {
        //dele b = new dele(ali);
        dele w = new dele(medo);
//          Console.WriteLine(w(2, 3));
        calc      d = new calc();
        delegatee del;

        del = d.sum;
        Console.WriteLine(del(10, 20));
        del = d.sub;
        Console.WriteLine(del(20, 10));
    }
예제 #17
0
        public void PipeReader()
        {
            // Open the named pipe.
            var server = new NamedPipeServerStream("Data");

            //Console.WriteLine("Waiting for connection...");
            server.WaitForConnection();

            //Console.WriteLine("Connected.");
            var br = new BinaryReader(server);

            //var bw = new BinaryWriter(server);

            while (true)
            {
                try
                {
                    var len = (int)br.ReadUInt32();            // Read string length
                    if (len == 0)
                    {
                        continue;
                    }
                    var      str     = new string(br.ReadChars(len)); // Read string
                    string[] clients = str.Split(';');
                    this._names     = new List <string>();
                    this._dataArray = new List <string[]>();
                    for (int i = 0; i < clients.Length; i++)
                    {
                        string name = clients[i].Split('%')[0];
                        this._names.Add(name);
                        string[] dates = (clients[i].Split('%')[1]).Split(',');
                        this._dataArray.Add(dates);
                    }

                    dele invokeDELE = new dele(this.updateDataGrid);
                    this.Invoke(invokeDELE);



                    //Console.WriteLine("Read: " + str);
                }
                catch (EndOfStreamException)
                {
                    break;                    // When client disconnects
                }
            }

            MessageBox.Show("Engine has disconnected");
            server.Close();
            server.Dispose();
        }
예제 #18
0
        static void Main(string[] args)
        {
            dele w = new dele(ww);

            w(23);


            //    dele d = new dele(clas.test);

            // dele qq = new dele(clas.test);
            //ww(20);
            //dele d = new dele(test);
            // Console.WriteLine (d(10);
        }
예제 #19
0
        static void Main(string[] args)
        {
            dele d = m1;

            d("정적 메서드");
            Program pr = new Program();

            d = pr.m2;
            d("인스턴스 메서드");

            d = Outer.m3;
            d("외부 정적 메서드");
            Outer O = new Outer();

            d = O.m4;
            d("외부 인스턴스 메서드");
        }
예제 #20
0
        static void Main()
        {
            dele d = m1;

            d("정적 메서드");
            _66_Delegate CS = new _66_Delegate();

            d = CS.m2;
            d("인스턴스 메서드");

            d = Outer.m3;
            d("외부 정적 메서드");
            Outer O = new Outer();

            d = O.m4;
            d("외부 인스턴스 메서드");
        }
예제 #21
0
        public void PipeReader()
        {
            // Open the named pipe.
            var server = new NamedPipeServerStream("NPtest1");

            //Console.WriteLine("Waiting for connection...");
            server.WaitForConnection();

            //Console.WriteLine("Connected.");
            var br = new BinaryReader(server);

            //var bw = new BinaryWriter(server);

            while (true)
            {
                try
                {
                    var len = (int)br.ReadUInt32();            // Read string length
                    if (len == 0)
                    {
                        continue;
                    }
                    var      str = new string(br.ReadChars(len)); // Read string
                    string[] ips = str.Split(';');

                    this.dataArray = ips;



                    dele invokeDELE = new dele(this.updateDataGrid);
                    this.Invoke(invokeDELE);



                    //Console.WriteLine("Read: " + str);
                }
                catch (EndOfStreamException)
                {
                    break;                    // When client disconnects
                }
            }

            MessageBox.Show("Engine has disconnected");
            server.Close();
            server.Dispose();
        }
예제 #22
0
        static void Main(string[] args)
        {
            //람다 1
            /*dele d2 =Add;*/

            //람다 2

            /*dele d = delegate(int a) { return a + 1; };
             * int k = d(3);
             * Console.WriteLine("k = " + k);
             */

            //람다 3
            dele d = (a => a + 1);
            int  k = d(3);

            Console.WriteLine("k = " + k);
        }
예제 #23
0
        // Método a enviar al Hilo.
        public void Metodo()
        {
            int  num        = 10;
            dele elDelegado = new dele(Mover);

            if (Thread.CurrentThread.Name.Equals("caballo0"))
            {
                elDelegado.Invoke(pbCaballo1, pbCaballo1.Location.Y, num);
                cola.Enqueue("Caballo 1");
            }
            else if (Thread.CurrentThread.Name.Equals("caballo1"))
            {
                elDelegado.Invoke(pbCaballo2, pbCaballo2.Location.Y, num);
                cola.Enqueue("Caballo 2");
            }
            else if (Thread.CurrentThread.Name.Equals("caballo2"))
            {
                elDelegado.Invoke(pbCaballo3, pbCaballo3.Location.Y, num);
                cola.Enqueue("Caballo 3");
            }
            else if (Thread.CurrentThread.Name.Equals("caballo3"))
            {
                elDelegado.Invoke(pbCaballo4, pbCaballo4.Location.Y, num);
                cola.Enqueue("Caballo 4");
            }
            else if (Thread.CurrentThread.Name.Equals("caballo4"))
            {
                elDelegado.Invoke(pbCaballo5, pbCaballo5.Location.Y, num);
                cola.Enqueue("Caballo 5");
            }
            else
            {
                // No hay más hilos.
            }

            string[] ca = cola.ToArray();
            foreach (var i in ca)
            {
                pos = lvLugares.Items.Add(i);
            }

            cola.Clear();
            this.btnReiniciar.Enabled = true;
        }
예제 #24
0
        static void Main(string[] args)
        {
            dele d = m1;

            d("정적 메서드");

            Program CS = new Program();

            d = CS.m2;
            d("인스턴스 메서드");

            d = Outer.m3;
            d("외부 정적 메소드");

            Outer o = new Outer();

            d = o.m4;
            d("외부 인스턴스 메서드");
        }
예제 #25
0
        static void Main(string[] args)
        {
            dele d = null;

            d += (n1, n2) => { int result = n1 + n2; Console.WriteLine(result); return(result); };
            d += (n1, n2) => { int result = n1 - n2; Console.WriteLine(result); return(result); };
            d += (n1, n2) => { int result = n1 * n2; Console.WriteLine(result); return(result); };
            d += (n1, n2) => { int result = n1 / n2; Console.WriteLine(result); return(result); };

            //d += delegate (int a, int b) { return a + b; };

            /* Add add = delegate (int a, int b) { return a + b; };
             * Sub sub = delegate (int a, int b) { return a - b; };
             * Mul mul = delegate (int a, int b) { return a * b; };
             * Div div = delegate (int a, int b) { return a / b; };
             *
             *
             * Console.Write("숫자를 입력해 주세요 : ");
             * int num1 = Convert.ToInt32(Console.ReadLine());
             * Console.Write("숫자를 입력해 주세요 : ");
             * int num2 = Convert.ToInt32(Console.ReadLine());
             *
             *
             * Console.Write("원하는 계산을 입력하세요 (1:+.2:-,3:*,4:/) : ");
             * int s = Convert.ToInt32(Console.ReadLine());
             *
             * switch (s)
             * {
             *   case 1:
             *       Console.WriteLine(add(num1, num2));
             *       break;
             *   case 2:
             *       Console.WriteLine(sub(num1, num2));
             *       break;
             *   case 3:
             *       Console.WriteLine(mul(num1, num2));
             *       break;
             *   case 4:
             *       Console.WriteLine(div(num1, num2));
             *       break;
             * }
             */
        }
예제 #26
0
    static void Main()
    {
        // {
        dele d = new dele();
//   //  delegat q = new delegat("medo", 20); // must take a method
//     delegat w;
        //d.citizen("medo", 23);
//     w = d.citizen;
//     d.person("aya", 88);
//     w = d.person; Console.WriteLine("_______________________________________\n\n");
////   w=new delegat(d.citizen("tiger",90)); //  لايجوز تعريف الميثود وضع قيم داخل الديلجيت .
        // pass delegate as parameter

        delegat q  = new delegat(d.citizen);
        delegat qq = new delegat(d.person);

        q("mgdy", 83);
        d.person(qq); Console.WriteLine(); // takes from delete qq from person
        d.person(q);                       // takes from delete q from citizen
    }
예제 #27
0
        public static void iniform()
        {
            try
            {
                string state;

                #region 从本地读取配置信息到内存
                string realDisplaySync = RealInterfaceFuction.ReadConfig("RealDisplaySync");
                if (realDisplaySync == "1")
                {
                    OprFuction.ReadRealConfigFromDB();//修改支持多个客户端显示设置同步  20180113
                }
                OprFuction.ReadRealDataDisplayConfig();
                OprFuction.ReadDefalutDataConfig();
                OprFuction.ReadCustomConfig();
                #endregion

                lock (StaticClass.allPointDtLockObj)
                {
                    StaticClass.AllPointDt = RealInterfaceFuction.GetAllPoint();

                    for (int i = 0; i < StaticClass.AllPointDt.Rows.Count; i++)
                    {
                        state = StaticClass.AllPointDt.Rows[i]["zt"].ToString();
                        if (state == StaticClass.itemStateToClient.EqpState24.ToString() || state == StaticClass.itemStateToClient.EqpState43.ToString())
                        {
                            StaticClass.AllPointDt.Rows[i]["statecolor"]   =
                                StaticClass.AllPointDt.Rows[i]["sszcolor"] =
                                    OprFuction.GetShowColor(state,
                                                            StaticClass.AllPointDt.Rows[i]["0tcolor"].ToString(),
                                                            StaticClass.AllPointDt.Rows[i]["bj"].ToString());
                        }
                        else if (state == StaticClass.itemStateToClient.EqpState44.ToString() || state == StaticClass.itemStateToClient.EqpState25.ToString())
                        {
                            StaticClass.AllPointDt.Rows[i]["statecolor"]   =
                                StaticClass.AllPointDt.Rows[i]["sszcolor"] =
                                    OprFuction.GetShowColor(state, StaticClass.AllPointDt.Rows[i]["1tcolor"].ToString(),
                                                            StaticClass.AllPointDt.Rows[i]["bj"].ToString());
                        }
                        else if (state == StaticClass.itemStateToClient.EqpState26.ToString())
                        {
                            StaticClass.AllPointDt.Rows[i]["statecolor"]   =
                                StaticClass.AllPointDt.Rows[i]["sszcolor"] =
                                    OprFuction.GetShowColor(state, StaticClass.AllPointDt.Rows[i]["2tcolor"].ToString(),
                                                            StaticClass.AllPointDt.Rows[i]["bj"].ToString());
                        }
                        else
                        {
                            StaticClass.AllPointDt.Rows[i]["statecolor"]   =
                                StaticClass.AllPointDt.Rows[i]["sszcolor"] =
                                    OprFuction.GetShowColor(state, "0", StaticClass.AllPointDt.Rows[i]["bj"].ToString());
                        }
                    }
                }
                real_s = new RealDisplayForm();

                real_s.Dock = DockStyle.Fill;

                real_del = real_s.Gv_init;

                _type_s = new DisplayNavagation();

                _type_s.Dock = DockStyle.Fill;

                _type_dele = _type_s.refresh;

                GetbjThread = new Thread(new ThreadStart(OprFuction.GetbjTh));
                GetbjThread.Start();

                InitRealWarGridControl();
                //Initalarm();
            }
            catch (Exception ex)
            {
                OprFuction.SaveErrorLogs(ex.Message, ex);
            }
        }
예제 #28
0
        public void PipeReader()
        {
            // Open the named pipe.
            var server = new NamedPipeServerStream("Data");

            //Console.WriteLine("Waiting for connection...");
            server.WaitForConnection();

            //Console.WriteLine("Connected.");
            var br = new BinaryReader(server);
            //var bw = new BinaryWriter(server);

            while (true)
            {
                try
                {
                    var len = (int)br.ReadUInt32();            // Read string length
                    if (len == 0)
                        continue;
                    var str = new string(br.ReadChars(len));    // Read string
                    string[] clients = str.Split(';');
                    this._names = new List<string>();
                    this._dataArray = new List<string[]>();
                    for (int i = 0; i < clients.Length; i++)
                    {
                        string name = clients[i].Split('%')[0];
                        this._names.Add(name);
                        string[] dates = (clients[i].Split('%')[1]).Split(',');
                        this._dataArray.Add(dates);

                    }

                    dele invokeDELE = new dele(this.updateDataGrid);
                    this.Invoke(invokeDELE);

                    //Console.WriteLine("Read: " + str);
                }
                catch (EndOfStreamException)
                {
                    break;                    // When client disconnects
                }
            }

            MessageBox.Show("Engine has disconnected");
            server.Close();
            server.Dispose();
        }
예제 #29
0
 public static void SetDelegate(out dele d)
 {
     int k = 5;
     d = delegate(int a, int b) { return a + b + k; };
 }
예제 #30
0
        //public void new_form_image(MemoryStream ms)
        //{
        //    Form form2 = new Form();
        //    //this.SuspendLayout();
        //    //
        //    // Form2
        //    //
        //    form2.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        //    form2.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        //    form2.AutoScroll = true;
        //    form2.ClientSize = new System.Drawing.Size(866, 461);
        //    form2.Name = "form2";
        //    form2.Text = "form2";
        //    form2.ResumeLayout(false);
        //    PictureBox pictureBox1 = new PictureBox();
        //    Image x = Image.FromStream(ms);
        //    form2.BackgroundImage = x;
        //    form2.Show();
        //}
        public void PipeReader()
        {
            // Open the named pipe.
            var server = new NamedPipeServerStream("Data");
            var Respond = new NamedPipeServerStream("Respond");
            //Console.WriteLine("Waiting for connection...");
            server.WaitForConnection();
            Respond.WaitForConnection();

            //Console.WriteLine("Connected.");
            var br = new BinaryReader(server);
            var bw = new BinaryWriter(Respond);
            //var bw = new BinaryWriter(server);

            Semaphore semaphoreObject = new Semaphore(3, 4);

            while (true)
            {
                try
                {
                    string str=Getting_Info(semaphoreObject, br, bw);

                    if (str.StartsWith("IMAGE"))
                    {
                        string tempSTR = (string)(str.Substring(6));
                        byte[] byteArrayIn = new byte[Int32.Parse(str.Substring(6))];
                        byteArrayIn = Getting_Image(semaphoreObject, br, bw, Int32.Parse(str.Substring(6)));
                        if (this.InvokeRequired)
                        {
                            this.Invoke((MethodInvoker)delegate
                            {
                                length = byteArrayIn.Length.ToString();
                            });

                        }
                        MemoryStream ms = new MemoryStream(byteArrayIn);
                        Image.FromStream(ms).Save("C:\\Users\\User\\Desktop\\IMAGE_IN_GUI.jpg");

                    }
                    else
                    {
                        string[] ClientAndPr = str.Split(',');

                        int n = index;
                        bool exist = false;
                        for (int i = 0; i < clients.Count; i++)
                            if (clients[i][0].Text == ClientAndPr[0])
                            {
                                dele2 invokeDELE2 = new dele2(this.removeC);
                                this.Invoke(invokeDELE2, i);
                                n = i;
                                index -= 1;
                                exist = true;
                                break;
                            }
                        index++;

                        if (!exist)
                            clients.Add(new Label[ClientAndPr.Length]);
                        else
                            clients[n] = new Label[ClientAndPr.Length];

                        dele invokeDELE = new dele(this.addC);
                        this.Invoke(invokeDELE, ClientAndPr, n);

                    }

                    //Console.WriteLine("Read: " + str);
                }

                catch(Exception e)
                {

                    MessageBox.Show(e.ToString());
                }
            }

            MessageBox.Show("Engine has disconnected");
            server.Close();
            server.Dispose();
        }
예제 #31
0
 public static void AddEvent(dele e)
 {
     sendMessage += e;
 }
예제 #32
0
 static int Calc(dele d)
 {
     return d(2, 3);
 }
예제 #33
0
        public void PipeReader()
        {
            // Open the named pipe.
            var server = new NamedPipeServerStream("NPtest1");

            //Console.WriteLine("Waiting for connection...");
            server.WaitForConnection();

            //Console.WriteLine("Connected.");
            var br = new BinaryReader(server);
            //var bw = new BinaryWriter(server);

            while (true)
            {
                try
                {
                    var len = (int)br.ReadUInt32();            // Read string length
                    if (len == 0)
                        continue;
                    var str = new string(br.ReadChars(len));    // Read string
                    string[] ips = str.Split(';');

                    this.dataArray = ips;

                    dele invokeDELE = new dele(this.updateDataGrid);
                    this.Invoke(invokeDELE);

                    //Console.WriteLine("Read: " + str);
                }
                catch (EndOfStreamException)
                {
                    break;                    // When client disconnects
                }
            }

            MessageBox.Show("Engine has disconnected");
            server.Close();
            server.Dispose();
        }
예제 #34
0
 public NewClass2(dele dele)
 {
     Dele = new dele(dele);
 }