I have this validation in mvc
public static ValidationResult validaUsuariosNaLista(Reuniao item) { var requeridos = item.Requeridos.Select(x => x.Login).Any(); var informados = item.Informados.Select(y => y.Login).Any(); var opcionais = item.Opcionais.Select(z => z.Login ? z.Login : null).Any(); if (requeridos == informados || requeridos == opcionais || informados == opcionais) return new ValidationResult(Resources.Validations.ValidaUsuarioMesmaLista); return ValidationResult.Success; } I try make a different if in line
var opcionais = item.Opcionais.Select(z => z.Login ? z.Login : null).Any(); but show error
Error 3 Cannot implicitly convert type 'string' to 'bool'
z.Login is a string
validation is to make that the field has no value it receives null.
Without that it bursts the error that is null.
I want him to receive null without giving error for it.
It selects the z.login on the list if the same login is in the other lists he'm the error.
How can I do this "if" that way?
.Select(z => z.Login)? Should do what I think you want, but then it isn't entirely clear what you want.z.Loginis string and you are trying to use it as a conditional part in conditiona(ternary) operatorz.Login ? z.Login : null???Anyand what it returns wonder why some manyDevelopersthese days neglect to use the debugger..