0
First I made this code:
for (int i = 0; i < vlstAcessos.Count - 1; i++)
{
if (vlstAcessos[i].DsURLTransacao == "frmANAAguardeProcesso.aspx")
transacaoANA = vlstAcessos[i].DsURLTransacao = "frmANAAguardeProcesso.aspx";
else if (vlstAcessos[i].DsURLTransacao == "frmPVListaProcessos.aspx")
transacaoPV = vlstAcessos[i].DsURLTransacao = "frmPVListaProcessos.aspx";
else if (vlstAcessos[i].DsURLTransacao == "frmGESStatusPriorizar.aspx")
transacaoGestor = vlstAcessos[i].DsURLTransacao = "frmGESStatusPriorizar.aspx";
else if (vlstAcessos[i].DsURLTransacao == "frmConsultarProcessos.aspx")
transacaoConsulta = vlstAcessos[i].DsURLTransacao = "frmConsultarProcessos.aspx";
}
Then I saw that this code is ugly and I did this:
transacaoPV = vlstAcessos.Any(l => l.DsURLTransacao == "frmPVListaProcessos.aspx").ToString();
I know perfectly that the lambda expression above will return a True or False. The question is: Is it possible with a Lambda I load a string variable with the expression value? That is, transacaoPV
take the value of: frmPVListaProcessos.aspx
These both replace the above IF, right?
transacaoGestor = vlstAcessos.Select(l => l.DsURLTransacao).FirstOrDefault(d => d == "frmGESStatusPriorizar.aspx");
transacaoPV = vlstAcessos.Select(l => l.DsURLTransacao).FirstOrDefault(d => d == "frmPVListaProcessos.aspx");
transacaoANA = vlstAcessos.Select(l => l.DsURLTransacao).FirstOrDefault(d => d == "frmANAAguardeProcesso.aspx");
transacaoConsulta = vlstAcessos.Select(l => l.DsURLTransacao).FirstOrDefault(d => d == "frmConsultarProcessos.aspx");
I will edit. In fact it should be inside the body the title.
– pnet
I can then say that I can substitute the previous if with those two, right? It’s cleaner code.
– pnet