0
i have a foreach running through my list and I want if() to be true it shows a message saying that there is already this value in the list and DON’T STORE this value on the list, someone knows how to do ??
foreach (Agendamento agenda in Agendamentos)
{
if (agenda.matricula.Equals(matricula) && agenda.horarioAtendimento.ToString("dd/MM/yyyy").Equals(maisDeUmDia))
{
Console.WriteLine("JA EXISTE UM ATENDIMENTO PARA ESTA DATA");
}
else
{
Console.WriteLine("NÃO EXISTE UM ATENDIMENTO PARA ESTA DATA");
}
}
I recommend using ready-made methods like
.Any
or.Contains
– Francisco