What’s the foreach up to?

Asked

Viewed 63 times

-3

    private List<Evento> ListaDeEventos = new List<Evento>();//cria a lista

    public void AddEvento(Evento e)//adiciona na lista
    {
        this.ListaDeEventos.Add(e);
    }

    public void CadastrarEvento()//adiciona valor nas variaveis
    {
        Evento evento = new Evento();
        Console.WriteLine("Diga o nome do evento: ");
        evento.nome = Console.ReadLine();
        Console.WriteLine("Diga o endereço do evento: ");
        evento.endereco = Console.ReadLine();
        Console.WriteLine("Diga a categoria do evento: ");
        evento.categoria = Console.ReadLine();
        Console.WriteLine("Descreva brevemente o evento: ");
        evento.descricao = Console.ReadLine();
        Console.WriteLine("Informe a data e hora do evento (Ex.: 01/01/2016 12:00:00): ");
        evento.horario = Convert.ToDateTime(Console.ReadLine());
        this.AddEvento(evento);

    }
    public void DisplayEventos() //metodo para mostrar o conteudo dos eventos
    {
        foreach (Evento e in this.ListaDeEventos)
        {

        }
    }
}

}

  • 1

    I advise you to take a look at how not to ask questions. And try to be more specific. What should this method do? What is the problem? What is the intention of foreach?

  • @jbueno sorry, the anxiety hit harder and I am new here. I beg your pardon.

  • I’m just giving you tips. Anyway, you can [Dit] your question at any time to improve it.

1 answer

2

I suppose your question is how iterate by noose foreach so that your method:

    public void DisplayEventos() { ... }

Display event information, which was previously stored in the event list:

    private List<Evento> ListaDeEventos = new List<Evento>();

Your method can be like this:

   public void DisplayEventos() //metodo para mostrar o conteudo dos eventos
    {
        foreach (Evento e in ListaDeEventos)
        {
            Console.Write("\nEvento: {0}", e.Nome);
            Console.Write("\nEndereço: {0}", e.Endereco);
            Console.Write("\nCategoria: {0}", e.Categoria);
            Console.Write("\nDescrição: {0}", e.Descricao);
            Console.Write("\nHorário: {0}", e.Horario);
        }
    }

iterate

1. t. d. do or say again; repeat, reiterate 2. t. d. álg make use of the iteration in

ETYMOLOGY

  • 'start again, renew, repeat'

SYNONYMS/VARIANTS

  • see synonymy of repeat

Source: Apple Dictionary 2.2.1 (178)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.