ForEach em Listlt;gt;

.NET

06/11/2008

Olá amigos, alguém poderia me dizer um exemplo de código ForEach em uma List<>?

Obrigado,
Alexei.


Buenolex

Buenolex

Curtidas 0

Respostas

Codename.v

Codename.v

06/11/2008

Segue o código!

//Cria uma nova generic list de string.
List<string> lstString = new List<string>();

//Insere cem valores no list.
for(int count = 0; count < 100; count++)
{
      lstString.Add("Valor " + count.ToString());
}

//Percorre a list usando foreach e exibe o valores na tela.
foreach(string str in lstString)
{
      Console.WriteLine(str);
}


Sem mais... 8)

Abraços!


GOSTEI 0
Proglele

Proglele

06/11/2008

Voce pode fazer assim:


Types.Categoria oCategoria = new Types.Categoria();

BLL.Categoria objCategoria = new BLL.Categoria();

objCategoria.SelecionarCategorias().
ForEach(delegate (Types.Categoria newObjCategoria)
{
// faz alguma coisa com alista.
}


GOSTEI 0
Ricardo Silva

Ricardo Silva

06/11/2008

Rapaizzzzz.....


GOSTEI 0
POSTAR