Beispiel #1
0
        private void btn_agregar_Click(object sender, EventArgs e)
        {
            Contacto ncon = new Contacto
                            (
                txtBx_nom.Text,
                txtBx_app.Text,
                txtBx_apm.Text,
                byte.Parse(txtBx_eda.Text),
                txtBx_ema.Text,
                txtBx_tel.Text
                            );

            if (agenda.Agregar(ncon) == 0)
            {
                txtBx_salida.Text = "Contacto Agregado" + Environment.NewLine;
            }
            else
            {
                txtBx_salida.Text = "Agenda llena" + Environment.NewLine;
            }
        }
        public int Agregar(Contacto nuevo)
        {
            int  pos      = 0;
            bool encontro = false;
            int  comp     = 0;

            while (pos < contactos.Length && !encontro)
            {
                if (contactos[pos] == null)
                {
                    encontro = true;
                }
                else
                {
                    comp = string.CompareOrdinal(nuevo.Nombre.ToLower(), contactos[pos].Nombre.ToLower());

                    if (comp < 0)
                    {
                        encontro = true;
                    }
                }

                if (!encontro)
                {
                    pos++;
                }
            }

            if (encontro)
            {
                Insertar(nuevo, pos);
            }
            else
            {
                return(1);
            }
            return(0);
        }