Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            Cast cast = delegate(double input)
            {
                return((int)input);
            };
            Cast cast1 = x => x.ToString().Length;

            double test  = 5.4926411;
            double test1 = 4.31;

            Console.WriteLine(cast(test));
            Console.WriteLine(cast1(test));

            Console.WriteLine(cast(test1));
            Console.WriteLine(cast1(test1));

            var multicastcast = cast;

            multicastcast += cast1;
            Console.WriteLine(multicastcast(test));

            d1 d1 = x => x.ToString();
            d2 d2 = x => x.ToString();

            int number = 10;

            Console.WriteLine(d1(number));
            Console.WriteLine(d2(number));
        }
Exemplo n.º 2
0
        public static void demodelegate()
        {
            d1 obj = (a) => (a + 5);


            Console.WriteLine(obj(5));
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            d1 d = new d1(demo);

            d(1);
            Console.ReadLine();
        }
Exemplo n.º 4
0
 // same as filter but with delegates
 public void FilterD(d1 d)
 {
     for (int i = 0; i < Length; i++)
     {
         if (!d(elements[i]))
         {
             RemoveAt(i--);
         }
     }
 }
Exemplo n.º 5
0
        public Id1 Create(
            ImmutableList <Id1IndexElement> value)
        {
            Id1 index = null;

            try
            {
                index = new d1(
                    value);
            }
            catch (Exception exception)
            {
                this.Log.Error("Exception message: " + exception.Message + " and stacktrace " + exception.StackTrace);
            }

            return(index);
        }
Exemplo n.º 6
0
 public static List <int> SumArrays(List <int> x, List <string> str, d1 func)
 {
     if (x.Count != str.Count)
     {
         List <int> t = new List <int>(-1);
         return(t);
     }
     else
     {
         List <int> t = new List <int>();
         for (int i = 0; i < x.Count; i++)
         {
             t.Add(func(x[i], str[i]));
         }
         return(t);
     }
 }
        void f8(Func <int, int> param)
        {
            d1 dd = delegate(out int b, int c, ref int d)
            {
                b = 0;
                c = 0; // Noncompliant
                d = 0;
            };

            param = i => 42; // Noncompliant

            e += delegate(out int foo1, int foo2, ref int foo3)
            {
                foo1 = 0;
                foo2 = 0; // Noncompliant
            };

            f8((int x) => x = 0); // Noncompliant
            f8((x) => x     = 0); // Noncompliant
            f8(
                (x) =>
            {
                return(0);
            });
            f8(
                (x) =>
            {
                x = 0;     // Noncompliant
                return(0);
            });
            f8(
                (int x) =>
            {
                return(0);
            });
            f8(
                (int x) =>
            {
                x = 0;     // Noncompliant
                return(0);
            });
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            List <int> x = new List <int>();

            x.Add(1);
            x.Add(2);
            x.Add(3);
            List <string> str = new List <string>();

            str.Add("2");
            str.Add("3");
            str.Add("4");
            d1 sum = Sum;


            List <int> l1 = SumArrays(x, str, sum);

            foreach (var i in l1)
            {
                Console.WriteLine(i);
            }
            Console.WriteLine();
            List <int> l2 = SumArrays(x, str,
                                      (x_1, str_1) => x_1 * Int32.Parse(str_1));

            foreach (var i in l2)
            {
                Console.WriteLine(i);
            }
            Console.WriteLine();
            Func <int, string, int> sum1 = Sum;
            List <int> l3 = SumArraysFunc(x, str, sum1);

            foreach (var i in l3)
            {
                Console.WriteLine(i);
            }
            Console.WriteLine();
            Console.ReadKey();
        }
Exemplo n.º 9
0
        public static void Main(string[] args)
        {
            Delegates obj = new Delegates();
            d1 <int>  pt  = obj.swap;

            int a = 10;
            int b = 20;

            pt(ref a, ref b);

            Console.WriteLine("A : " + a);
            Console.WriteLine("B : " + b);

            double c = 100;
            double d = 200;

            d1 <double> pd = obj.swap;

            pd(ref c, ref d);

            Console.WriteLine("C : " + c);
            Console.WriteLine("D : " + d);
        }
Exemplo n.º 10
0
 return(!Equals(d1, d2));
Exemplo n.º 11
0
        private void AtenderServidor()
        {
            while (true)
            {
                //recibimos  mensaje del servidor
                byte[] msgr = new byte[2000];
                server.Receive(msgr);
                string[] trozos = Encoding.ASCII.GetString(msgr).Split('/'); // partimos por la barra, [] tienes al menos 2 strings
                int      codigos;
                try
                {
                    codigos = Convert.ToInt32(trozos[0]);// el primer string lo convierte a numero
                    string mensaje;
                    int    nform;
                    int    men;
                    string el_nombre;
                    switch (codigos)
                    {
                    case 1:     //Consulta 1
                        mensaje = trozos[1].Split('\0')[0];
                        Funcion1(mensaje);
                        break;

                    case 2:    //Consulta 2
                        mensaje = trozos[1].Split('\0')[0];
                        Funcion2(mensaje);
                        break;

                    case 3:    //Consulta3
                        mensaje = trozos[1].Split('\0')[0];
                        Funcion3(mensaje);
                        break;

                    case 4:     //recibimos notificacion
                        mensaje = trozos[1].Split('\0')[0];
                        d1 t = new d1(ParticionLogin);
                        Invoke(t, new object[] { mensaje });

                        break;

                    case 6:    //Chat
                        mensaje = trozos[1].Split('\0')[0];
                        Funcion6(mensaje);
                        break;

                    case 7:    // recibo lista conectados

                        break;

                    case 8:
                        mensaje = trozos[1].Split('\0')[0];
                        listBox1.Items.Clear();
                        string elusuario = mensaje;
                        partir_lista_conectados(mensaje);
                        break;

                    case 9:
                        mensaje = trozos[1].Split('\0')[0];
                        d2 d = new d2(MeInvitan);
                        Invoke(d, new object[] { mensaje, mipropionombre });
                        break;

                    case 10:
                        mensaje = trozos[1].Split('\0')[0];
                        d1 h = new d1(SIoNO);
                        Invoke(h, new object[] { mensaje });
                        break;

                    case 11:
                        nform   = Convert.ToInt32(trozos[1]);
                        mensaje = trozos[2].Split('\0')[0];
                        formularios[nform].Tomachat(mensaje);
                        break;

                    case 12:
                        nform   = Convert.ToInt32(trozos[1]);
                        mensaje = trozos[3].Split('\0')[0];
                        formularios[nform].Cartas_principio(mensaje);
                        int primeraCarta = Convert.ToInt32(trozos[2]);
                        formularios[nform].Espejo(primeraCarta);
                        break;

                    case 13:
                        nform = Convert.ToInt32(trozos[1]);
                        formularios[nform].TuTurno();
                        break;

                    case 14:
                        nform = Convert.ToInt32(trozos[1]);
                        men   = Convert.ToInt32(trozos[2].Split('\0')[0]);
                        formularios[nform].Espejo(men);
                        break;

                    case 15:
                        nform = Convert.ToInt32(trozos[1]);
                        men   = Convert.ToInt32(trozos[2].Split('\0')[0]);
                        formularios[nform].CartaRobada(men);
                        break;

                    case 16:
                        nform     = Convert.ToInt32(trozos[1]);
                        el_nombre = trozos[2].Split('\0')[0];
                        formularios[nform].Notificacion_Ganador(el_nombre);
                        break;
                    }
                }

                catch (FormatException)
                {
                    string mensaje = "0/" + mipropionombre;
                    byte[] msg     = System.Text.Encoding.ASCII.GetBytes(mensaje);
                    server.Send(msg);
                    MessageBox.Show("Error 404: Conexión No Encontrada! Reinicia la aplicación.");

                    server.Shutdown(SocketShutdown.Both);
                    server.Close();
                    Application.Exit();
                    atender.Abort();
                }
            }
        }