13
What is the purpose of the operator =>
in the use of lists List<T>
, I am starting to use generic lists and came across this operator, it is only used in this method LISTA.ForEach(i => Console.WriteLine(i));
?
Below follows my example for illustration:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ListaGenericaCollection
{
class Program
{
static void Main(string[] args)
{
List<string> LISTA = new List<string>();
string opcao = "1";
while (opcao.Equals("1"))
{
Console.WriteLine("Digite um nome para inserir na lista: ");
string nome = Console.ReadLine();
LISTA.Add(nome);
Console.WriteLine("Deseja inserir outro nome na lista? 1-SIM | 2-NAO:");
opcao = Console.ReadLine();
}
LISTA.Sort();
Console.WriteLine("A lista tem " + LISTA.Count + " itens:");
LISTA.ForEach(i => Console.WriteLine(i));
Console.ReadKey();
}
}
}
I also noticed that the variable i
no data type has been specified for her, she is a generic type?
Only a small detail. In the last example, the parameter of
WriteLine
should beobj
.– Jéf Bueno
Sure, damn C V :)
– Maniero
To complement only, the nickname of the "lambda operator" is Fat Arrow - Fat Arrow in Free Translation.
– Thiago Lunardi