What is the purpose of the =>
operator in the use of List<T>
lists, I'm starting to use generic lists and I came across this operator, it is only used in this method LISTA.ForEach(i => Console.WriteLine(i));
?
Below is 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 i
variable was not specified as a data type for it, is it a generic type?