Пример #1
0
        /// <summary>
        /// Muestro el Changuito y TODOS los Productos
        /// </summary>
        /// <returns>un string con los datos</returns>
        public string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("Tenemos {0} lugares ocupados de un total de {1} disponibles", this.productos.Count, this.espacioDisponible);
            sb.AppendLine("");
            for (int i = 0; i < this.productos.Count; i++)
            {
                if (this.productos[i] is Snacks)
                {
                    Snacks paraMostrarSnacks = (Snacks)this.productos[i];
                    sb.AppendLine(paraMostrarSnacks.Mostrar());
                }
                if (this.productos[i] is Dulce)
                {
                    Dulce paraMostrarDulce = (Dulce)this.productos[i];
                    sb.AppendLine(paraMostrarDulce.Mostrar());
                }
                if (this.productos[i] is Leche)
                {
                    Leche paraMostrarLeche = (Leche)this.productos[i];
                    sb.AppendLine(paraMostrarLeche.Mostrar());
                }
            }

            return(sb.ToString());
        }
Пример #2
0
        /// <summary>
        /// Expone los datos del elemento y su lista (incluidas sus herencias)
        /// SOLO del tipo requerido
        /// </summary>
        /// <param name="c">Elemento a exponer</param>
        /// <param name="ETipo">Tipos de ítems de la lista a mostrar</param>
        /// <returns></returns>
        public string Mostrar(Changuito c, ETipo tipo)
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < c.productos.Count; i++)
            {
                if (tipo == Changuito.ETipo.Dulce)
                {
                    if (this.productos[i] is Dulce)
                    {
                        Dulce paraMostrarDulce = (Dulce)this.productos[i];
                        sb.AppendLine(paraMostrarDulce.Mostrar());
                    }
                }
                if (tipo == Changuito.ETipo.Snacks)
                {
                    if (this.productos[i] is Snacks)
                    {
                        Snacks paraMostrarSnacks = (Snacks)this.productos[i];
                        sb.AppendLine(paraMostrarSnacks.Mostrar());
                    }
                }
                if (tipo == Changuito.ETipo.Leche)
                {
                    if (this.productos[i] is Leche)
                    {
                        Leche paraMostrarLeche = (Leche)this.productos[i];
                        sb.AppendLine(paraMostrarLeche.Mostrar());
                    }
                }
                if (tipo == Changuito.ETipo.Todos)
                {
                    c.ToString();
                }
            }
            return(sb.ToString());
        }