How to start a variable correctly?

5

Is there a difference between these two ways to start a variable?

List<classeterapeutica> itens = new List<classeterapeutica>();
modelOff.classeterapeuticas.ToList();

or

List<classeterapeutica> itens = modelOff.classeterapeuticas.ToList();
    
asked by anonymous 11.04.2017 / 02:25

1 answer

4

It is not a matter of being correct, but initializing a variable with a value to change this value on the next line does not make sense, so the second code is preferable. Only assign a value to a variable if this value will be used somewhere. If it is discarded without use it is a bad thing.

    
11.04.2017 / 02:27