0
I don’t know a good way to ask this, I googled it but I didn’t think what I wanted, I know the expression variavel?.atributo
which makes the code only try to catch the attribute if the variable has value, if it does not return null
I also know the expression variavel ?? 0
which causes the code to return 0 value after the ??
if the value is null
The point is, I’ve seen codes where these two are used together, but in my code I end up getting a null exception
.
An example of my current code:
var notaComp = notasFiltradas?.Where(x => x.TipoAvaliacao == (int)TipoAvaliacaoParcial.AutoAvaliacao)?.SingleOrDefault().Nota ?? 0;
See in the null exeption description which field is null.
– ramaral
the enumeration did not generate results, it is this part here that comes before var notasFiltradas = Model.Notas.Where(x => x.Idcompetencia == competencia.Idcompetencia)
– Lucas
There’s nothing ternary in this code.
– Maniero